一段时间后,砌体或我的滚动脚本冻结了Firefox

时间:2012-11-13 23:27:19

标签: jquery scroll jquery-masonry

我写了一个小的无尽滚动脚本,用于布局的砌体, 在一些ajax调用之后,浏览器变得越来越慢(冻结)......

var $container = jQuery('#container');

    $container.masonry({
      itemSelector: '.box',
      columnWidth: 100,


      isAnimated : true,
      isFitWidth : false

    }).imagesLoaded(function() {
   $container.masonry('reload');
  });



var isLoading = false;
var endofdata = false;
var page=1;
$(window).scroll(function() {

    if ( $(window).scrollTop()+1 >= ( $(document).height() - $(window).height() ) )
    {
        if ( endofdata )
            return false;

        if (isLoading) {

            return false; // don't make another request, let the current one complete, or
            // ajax.abort(); // stop the current request, let it run again
        }
        isLoading =true;
        ajaxLoadActivity('bottom', true);
    }

});
var box;
function ajaxLoadActivity(one, two) {
     page=page+1;

     $.post('api.php', {'action' : "next", 'next' : page },
        function(data){
                 if(data == null)
                     endofdata=true;

                 jQuery.each(data, function(index, value){                        
                     box+="<div class=\"box\"><a href=\"page/"+value.id +"\">#" +value.id + "</a> " +value.data+"</div>";

                 });
                 boxes = $(box);
                 $container.append(boxes);
                 var $newElems = $( boxes ).css({ opacity: 0 });
                 $newElems.imagesLoaded(function(){
                     $newElems.animate({ opacity: 1 });
                     $container.masonry( 'appended', $newElems, true );

                 });


                 box="";
                 isLoading=false;



                }
            );
}

工作实例 http://www.dasmerkendienie.com/ (滚动一段时间后会发生错误)

任何形式的帮助将不胜感激

最好的问候 安德烈亚斯

btw:firefox上出错,而​​不是google chrome

1 个答案:

答案 0 :(得分:0)

问题是isAnimated标志,当我加载更多时,我的浏览器卡住了 超过50个元素。 我不确定它是否是我的滚动脚本,砖石或jquery中的错误。 但至少它解决了我的问题。

var $container = jQuery('#container');

$container.masonry({
  itemSelector: '.box',
  columnWidth: 100,


  isAnimated : false,
  isFitWidth : false

}).imagesLoaded(function() {   $container.masonry('reload');  });