gpt4 book ai didi

javascript - 如何检查同位素是否已初始化?

转载 作者:行者123 更新时间:2023-11-28 06:37:54 24 4
gpt4 key购买 nike

我正在 ajax 调用中添加新项目,每次单击时都会检查同位素是否已初始化,同位素布局会放置所有新项目,但不会发生以下情况

if($("#list").data('isotope')) {
alert("hello");
}

是否有办法检查同位素是否已初始化?

最佳答案

我让它工作的唯一方法是检查变量。

var myVar = false;
jQuery.fn.almComplete = function(alm){ <-- my ajax callback
if(myVar) { <-- my var is true, means isotope is initialised
do something
} else {
myVar = true; <-- set my var tot rue as isotope is not initialised and
start isotope
}
});

我在ajax调用之前将var设置为false,然后当我加载我的项目时,我首先检查我的var是否设置为true,如果没有,我将其设置为true并加载同位素。当我再次加载项目时,我的 var 将设置为 true,就像我第一次启动 isotope 时设置的那样,因此我知道 isotope 已启动。

关于javascript - 如何检查同位素是否已初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34107841/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com