jQuery Infinite-Scroll - 当滚动速度很快时,事件会多次触发

时间:2012-04-02 04:45:38

标签: javascript jquery infinite-scroll

如果我滚动页面,jQuery Infinite Scroll的事件将会发生两次三次。我可以避免这种情况发生吗?当下一页加载时,jQuery Infinite Scroll的事件无法激发谢谢。

$(function(){
    var speed = 1000;
    var container = $('#sharelist');
    container.imagesLoaded(function(){
      container.masonry({
        itemSelector: '.share',
        singleMode: true,
        columnWidth: 242,
        isFitWidth: true,
        animate: true,
        animationOptions: {
            duration: speed,
            queue: false
        }
      });
    });
    container.infinitescroll({
      navSelector  : '.page',     
      nextSelector : 'a.next',
      itemSelector : 'div[class=share]',
      loading: {
          finishedMsg: '报告,后面没有了哦.',
          img: 'image/icon_waiting.gif',
          msgText:'加载中'
        }
      },
      function( newElements ) {
        var newElems = $(newElements).css({ opacity: 0 });
        newElems.imagesLoaded(function(){
          newElems.animate({ opacity: 1 });
          container.masonry( 'appended', newElems, true );
          $('.namecard').floatUserInfo();
        });
      }
    );
    $("img").lazyload({
        placeholder : "image/grey.gif",
        effect      : "fadeIn"
     });
  });

1 个答案:

答案 0 :(得分:3)

有很多关于限制调整大小事件的现有文献,你在这里有基本相同的关注点。典型的解决方案涉及调度异步处理程序,然后一次只允许一个处于挂起状态。最强大的(?)方式是取消和替换旧的处理程序。

例如:

http://benalman.com/code/projects/jquery-throttle-debounce/examples/throttle/