jQuery Isotope queue shuffle/randomize animation

余生长醉 提交于 2019-12-13 02:06:22

问题


I would like to set the jQuery Isotope shuffle method to to perform an animated shuffle of the loaded DOM elements every 30 seconds that someone is on the page with the plugin loaded.

I have had success tying the animation to a .hover() event, but I cannot seem to get it to fire when I use setInterval() or .queue(). I want the animation to fire regardless of user interaction/input.

var iso_shuffle = function() {
    $('#isotope').isotope('shuffle');
}

setInterval(iso_shuffle(), 2500);

Why does the previous code not trigger the randomization, yet this does:

$('#isotope').hover(function() {
    iso_shuffle()
});

Cheers


回答1:


iso_shuffle() calls the function immediately. The function returns nothing. So your setInterval is actually doing the equivalent of:

setInterval(undefined, 2500);

You want to use the function name as the callback for setInterval:

setInterval(iso_shuffle, 2500);



回答2:


You need to pass the function itself, not its return value:

setInterval(iso_shuffle, 2500);


来源:https://stackoverflow.com/questions/14043879/jquery-isotope-queue-shuffle-randomize-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!