问题
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