The setInterval () method in jQuery and jquerysetinterval

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.