JavaScript Racing Lights

Source: Internet
Author: User

1. I read a tutorial case of a marquee, and after a while I wrote a simple marquee. The problems encountered in the process are hereby recorded.

The code is as follows:

<! DOCTYPE Html>"Content-type"Content="text/html;charset=gb2312"> <title> Jane &nbsp; Burrow &nbsp; &nbsp; tube &nbsp; &nbsp; after &nbsp; set &nbsp;</title> 'Button'Value='Stop Titleloop'Id='Stoploop'/><script src='C:\Users\wujy1\Desktop\html\js\jquery-3.1.1.min.js'></script><script>function Titleloop () {//implementing a title Loop        vartitle=$ ('title'). text (); FirstWord=title[0];//Save the first character of a stringTitle=title.substring (1);//intercepts the first character of a string        /*Document.title=title+firstword; Use this method to compare memory consumption.                For example: var lang = "Java";                Lang = lang + "Script"; Start by creating a new string that can hold 10 characters, then populate the string with "Java" and "script", and the final step is to destroy the original string "Java" and "script", because these two strings are useless.        However, in a lower version of the browser (such as IE6), the string stitching speed is a process that consumes a performance. */        varArry=array (Title,firstword);//position the new string and the first character as an array (note the order) and use the Join method to stitch togetherTitle=arry.join (""); $('title'). Text (Title);//Change title Content    }          varLoop=setinterval ("Titleloop ()", -);//Enable loops$('#stoploop'). Click (function () {clearinterval (loop);});//End Loop</script></body>

Problem:

When I want to end the loop, the following code is not used to end the process:

$ (' #stoploop '). Click (function() {Clearinterval (SetInterval ("Titleloop ()", 500))

View clearinterval Description: The parameter of the Clearinterval () method must be the ID value returned by SetInterval ().

Use this time:

var loop=setinterval ("Titleloop ()", +);  Console.log (loop);  #返回1console. Log (SetInterval ("Titleloop ()")#返回2console. Log (SetInterval ("Titleloop ()", 500)) # Returns 3

So the loop must be assigned to the variable, and then the loop is closed.

At this point, it is assumed that whenever a setinterval () is defined, his ID value is incremented by 1. Verify that:

JavaScript Racing Lights

Related Article

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.