jQuery自定义内容滚动条 - malihu |窗口调整大小时更改SnapAmount

时间:2016-02-21 18:00:57

标签: javascript jquery jquery-plugins

我在整页中使用custom content scroller,在页面中使用snapAmount作为完整高度部分。 如何在Window调整大小时更改SnapAmount值?

var amount = Math.max.apply(Math, $(window).map(function () {
    return $(this).outerHeight(true);
}).get());

$('body').mCustomScrollbar({
    keyboard: {scrollType: 'stepped', scrollAmount: amount},
    snapAmount: amount,
    mouseWheel: {scrollAmount: amount},
});

//window height
var wheight = $(window).height(); //get height of the window

$('.fullheight').css('height', wheight);

$(window).resize(function() {
   var wheight = $(window).height(); //get height of the window
   $('.fullheight').css('height', wheight);
}); //on resize

1 个答案:

答案 0 :(得分:0)

没有snapAmount,它对我有用:



var PrevScrollPosition = 0;


$('body').mCustomScrollbar({
  callbacks: {
    onScroll: function() {

      function scrollToActive(toPosition) {
        $('.mCustomScrollbar').mCustomScrollbar('scrollTo', toPosition, {
          scrollInertia: 500,
          scrollEasing: "easeInOut"
        });
      }

      var scrollPosition = Math.abs(parseInt($('.mCSB_container').css('top'))),
        pervFullHeightActive = $('.fullheight.active');

      fullHeight.each(
        function() {
          var ts = $(this),
            thisTopOffset = ts.offset().top,
            thisHeight = ts.height(),
            thisBottomOffset = thisTopOffset + thisHeight,

            fullheightActive = $('.fullheight.active'),
            fullheightActiveHeight = fullheightActive.height(),

            windowHeight = $(window).height();


          if (PrevScrollPosition < scrollPosition && fullheightActive.next().length) {
            if (thisTopOffset < windowHeight && (fullheightActive.offset().top + fullheightActive.height()) < windowHeight) {
              fullheightActive.removeClass('active');
              $(this).addClass('active');
              scrollToActive($('#' + $('.fullheight.active').attr('id')));
            }
          }
          if (PrevScrollPosition > scrollPosition && pervFullHeightActive.offset().top > 1) {
            if (thisBottomOffset < windowHeight) {
              fullheightActive.removeClass('active');
              $(this).addClass('active');
              scrollToActive($('.fullheight.active').position().top + $('.fullheight.active').height() - windowHeight);
            }
          }
        }
      );

      PrevScrollPosition = scrollPosition;
    }
  }
});
&#13;
&#13;
&#13;