Действия

Widget

Порталы: различия между версиями

Материал из ВикиВоины

(Отмена правки 411977, сделанной Laurent Nautilus (обсуждение))
Метка: отмена
Строка 153: Строка 153:
 
   var portalContentsTop = portalContents.offset().top;
 
   var portalContentsTop = portalContents.offset().top;
  
$(window).on('scroll hashchange', function() {
+
  $(window).scroll(function() {
  var scrollTop = $(window).scrollTop();
+
    var scrollTop = $(window).scrollTop();
  $('.sections_title, .period_title').each(function() {
+
 
      var sectionId = $(this).attr('id');
+
    $('.sections_title, .period_title').each(function() {
      var sectionTop = $('#' + sectionId).offset().top;
+
        var sectionId = $(this).attr('id');
      var sectionBottom = sectionTop + $('#' + sectionId).outerHeight();
+
        var sectionTop = $('#' + sectionId).offset().top;
      if (scrollTop >= sectionTop && scrollTop < sectionBottom) {
+
        var sectionBottom = sectionTop + $('#' + sectionId).outerHeight();
          $('.portal-contents a').removeClass('active');
+
 
          $('.portal-contents a[href="#' + sectionId + '"]').addClass('active');
+
        if (scrollTop >= sectionTop && scrollTop < sectionBottom) {
      }
+
            $('.portal-contents a').removeClass('active');
  });
+
 
  if (scrollTop > sidebarTop && scrollTop > portalContentsTop && !isFixed) {
+
            $('.portal-contents a[href="#' + sectionId + '"]').addClass('active');
      portalContents.addClass('fixed');
+
        }
      isFixed = true;
+
    });
  } else if ((scrollTop <= sidebarTop || scrollTop <= portalContentsTop) && isFixed) {
+
 
      portalContents.removeClass('fixed');
+
    if (scrollTop > sidebarTop && scrollTop > portalContentsTop && !isFixed) {
      isFixed = false;
+
        portalContents.addClass('fixed');
  }
+
        isFixed = true;
 +
    } else if ((scrollTop <= sidebarTop || scrollTop <= portalContentsTop) && isFixed) {
 +
        portalContents.removeClass('fixed');
 +
        isFixed = false;
 +
    }
 
});
 
});
  

Версия 10:24, 5 мая 2024