开发者

jQuery automate function call

开发者 https://www.devze.com 2023-01-21 21:57 出处:网络
How do I call a given function every X seconds? In this case, I made a function th开发者_StackOverflowat scrolls some images. I want the image to change based on a given interval of time, for exampl

How do I call a given function every X seconds?

In this case, I made a function th开发者_StackOverflowat scrolls some images. I want the image to change based on a given interval of time, for example, every 5 seconds, but I really have no idea.


No need for jQuery here, plain JavaScript using setInterval() will do:

function myFunctionName() {
  //change image here
}
setInterval(myFunctionName, 5000);

Or the anonymous version:

setInterval(function () {
  //change image here
}, 5000);


Try

setInterval(function, Xseconds);


If you want jQuery to do it for you, there is a plugin, jquery.cycle.all. This will make creating the transition very easy. If you're using jQuery already, then it might be a good fit. Otherwise, the setInterval is easy to work with that other posters already mentioned.

0

精彩评论

暂无评论...
验证码 换一张
取 消