开发者

Javascript or JQuery - How do I change the background color every fixed-time-interval? [duplicate]

开发者 https://www.devze.com 2023-03-11 02:52 出处:网络
This question already has answers here: Closed 11 years ago. Exact Duplicate: how can I execute javascript code every a specific time interval ?
This question already has answers here: Closed 11 years ago.

Exact Duplicate:

how can I execute javascript code every a specific time interval ?

开发者_开发知识库

Is there an efficient method for causing a javascript (ChangeDivBG(), in my case) function to execute every fixed time interval?


setInterval(ChangeDivBG, 1000); // 1000 is time interval in miliseconds - 1000ms=1sec


You can use setInterval function

setInterval(ChangeDivBG, delay);

If you want to pass an argument:

setInterval(function(color){ ChangeDivBG(color) }, delay);

If you pass an argument like this:

setInterval(ChangeDivBG, delay, color);

It won't work in IE(under IE9), be careful about that.


use setInterval (func, t).

setInterval(ChangeDivBG, 1000)

t is in milliseconds.

0

精彩评论

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

关注公众号