Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
即使在重新加载或重新播放之后,jquery也会显示重叠的元素_Jquery_Jquery Isotope - Fatal编程技术网

即使在重新加载或重新播放之后,jquery也会显示重叠的元素

即使在重新加载或重新播放之后,jquery也会显示重叠的元素,jquery,jquery-isotope,Jquery,Jquery Isotope,我有一个函数,比如说函数forajaxrequestanddisplaydata(…),它执行ajax调用并将数据写入/附加到html 当我跟随时,一切都很好 $(document).ready(function() { functionForAjaxRequestAndDisplayData(...); functionForAjaxRequestAndDisplayData(...); : functionForAjaxRequestAndDisplayDat

我有一个函数,比如说函数forajaxrequestanddisplaydata(…),它执行ajax调用并将数据写入/附加到html

当我跟随时,一切都很好

$(document).ready(function() {
    functionForAjaxRequestAndDisplayData(...);
    functionForAjaxRequestAndDisplayData(...);
    :
    functionForAjaxRequestAndDisplayData(...);
});

function functionForAjaxRequestAndDisplayData(...){
    :
    $('#container').append(ajaxresponseElement);      
}

function applyIsotop(){
    isotopIntialized = true;
    $('#Feeds').imagesLoaded( function(){
        $('#Feeds').isotope({
          sortBy : 'random',
          layoutMode: 'masonry',
          itemSelector : '.Feed'
        });
    });
}

$(window).load(function(){
    applyIsotop();
});
但是执行如此多的ajax请求会使页面加载速度变慢。由于jQuery应用于$(window.load();ie加载后,应用masorny视图的延迟在屏幕上清晰可见

为了克服这个问题,我决定将ajax函数调用分为以下两部分:

$(document).ready(function() {
    functionForAjaxRequestAndDisplayData(...);
    functionForAjaxRequestAndDisplayData(...);
    functionForAjaxRequestAndDisplayData(...);
    functionForAjaxRequestAndDisplayData(...);
});

function loadRest(){
    functionForAjaxRequestAndDisplayData(...);
    functionForAjaxRequestAndDisplayData(...);
    :
    functionForAjaxRequestAndDisplayData(...);
}

$(window).load(function(){
    applyIsotop();
    loadRest();
});

function functionForAjaxRequestAndDisplayData(...){
    :
    if(isotopIntialized == false){
                $('#container').append(ajaxresponseElement);
          }else{
              $('#container').append(ajaxresponseElement).isotope( 'insert',$(ajaxresponseElement),function(){
                    $('#container').isotope( 'reLayout')
              })
          }
}
但这种解决方案导致容器中的元素重叠。如果在添加或插入项后使用“relayat”,则所有列中的所有元素都会重叠。如果在添加或插入项后使用“reloadeitems”,则第一列中的某些元素会重叠。然而,当我使用同位素过滤器时,所有项目都正确地重新对齐

我试着调用同位素过滤器,如下所示

$(window).load(function(){
    applyIsotop();
    loadRest();
    wait(1000);
    $('#container').isotope({ filter: '*' });
});

但它也不起作用,因为它在所有ajax调用完成之前执行。

使用以下代码来摆脱重叠问题:

$container.append(divs).isotope('appended', divs, function () {
    $container.isotope('reLayout');
});

当我定义
filter:'*'
同位素属性时,我遇到了较少重叠的问题。7年前,它仍然适用于加载外部资源,如shopify的but按钮。