The setInterval () method in jQuery and jquerysetinterval
Definition and usage:
The setInterval () method can call functions or computation expressions according to the specified period (in milliseconds.
The setInterval () method does not stop calling the function until clearInterval () is called or the window is closed. The ID value returned by setInterval () can be used as a parameter of the clearInterval () method.
Var time = 0;
Usage 1:
Function jump (){............ // Function content} time = setInterval ("jump", 5000); // calls the explain function every five seconds
When paused
$ (""). Hover (function () {clearInterval (time), function () {time = setInterval ("jump", 5000 );}})
Usage 2:
Function autoPlay () {time = setInterval (function (){............ // Function content}, 5000);} autoPlay (); // call a function
When pause is required
$ (""). Hover (function () {clearInterval (time), function () {autoPlay ();}})
Summary:
The first method is clear. First, set a function and call it from the row through setInterval, but it is difficult to call it elsewhere;
The second method looks messy. Write down the self-called function in setInterval, set a famous function to him, and call the famous function to implement the function automatically. It is more convenient to call the function elsewhere.
The above is my personal opinion. I hope you can give more advice.