Действия

Widget

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

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

(Отмена правки 411963, сделанной Laurent Nautilus (обсуждение))
Метка: отмена
Строка 145: Строка 145:
 
   var contentItemWrapList = linkList.clone();
 
   var contentItemWrapList = linkList.clone();
 
   contentItemWrapList.find('.sidebar').remove();
 
   contentItemWrapList.find('.sidebar').remove();
 +
 +
  setTimeout(function() {
 +
    $('.contents-item-wrap').append(contentItemWrapList);
 +
  }, 1000);
 +
 +
  var sidebarTop = $('.sidebar:last').offset().top;
 +
  var portalContentsTop = portalContents.offset().top;
  
 
   $(window).scroll(function() {
 
   $(window).scroll(function() {
  var scrollTop = $(window).scrollTop();
+
    var scrollTop = $(window).scrollTop();
  
  // Перебираем заголовки в содержании
+
     if (scrollTop > sidebarTop && scrollTop > portalContentsTop && !isFixed) {
  $('#sidebar:last .portal-contents a').each(function() {
+
       portalContents.addClass('fixed');  
    var target = $(this.hash);
+
       isFixed = true;
     if (target.length) {
+
    } else if ((scrollTop <= sidebarTop || scrollTop <= portalContentsTop) && isFixed) {
       var targetTop = target.offset().top;
+
       portalContents.removeClass('fixed');  
       var targetBottom = targetTop + target.outerHeight();
+
       isFixed = false;
 
 
      // Проверяем, находится ли заголовок в области видимости
 
      if (scrollTop >= targetTop && scrollTop < targetBottom) {
 
        $(this).addClass('active');
 
       } else {
 
        $(this).removeClass('active');
 
       }
 
 
     }
 
     }
 
   });
 
   });
  
  // Код для фиксированного меню
+
$(window).scroll(function() {
  var sidebarTop = $('.sidebar:last').offset().top;
+
    var currentPosition = $(this).scrollTop();
  var portalContentsTop = $('.portal-contents').offset().top;
+
    $('.sections_title, .period_title').each(function() {
 +
        var sectionTop = $(this).offset().top;
 +
        var sectionId = $(this).attr('id');
 +
        if (currentPosition >= sectionTop) {
 +
            $('.side-nav li').removeClass('active');
 +
            var activeElement = $('.side-nav li').find('a[href="#' + sectionId + '"]').parent();
 +
            activeElement.addClass('active');
 +
        }
 +
    });
 +
});
  
  if (scrollTop > sidebarTop && scrollTop > portalContentsTop && !isFixed) {
 
    $('.portal-contents').addClass('fixed');
 
    isFixed = true;
 
  } else if ((scrollTop <= sidebarTop || scrollTop <= portalContentsTop) && isFixed) {
 
    $('.portal-contents').removeClass('fixed');
 
    isFixed = false;
 
  }
 
});
 
  
  

Версия 09:49, 5 мая 2024