Home > Web Front-end > JS Tutorial > A brief discussion on the setInterval event of js_Basic knowledge

A brief discussion on the setInterval event of js_Basic knowledge

WBOY
Release: 2016-05-16 16:28:51
Original
1507 people have browsed it

The setInterval() method will keep calling the function until clearInterval() is called or the window is closed. The ID value returned by setInterval() can be used as an argument to the clearInterval() method.
setinterval() usage

setInterval(code,millisec[,"lang"])

The following two parameters code is your js code, millisec is the time interval, measured in milliseconds

Copy code The code is as follows:





                                                                                                    var one=document.getElementById('one')
        var x=0;
          var y=0;
        var xs=10;
          var ys=10;
           function scroll(){
                 x =xs;
            y =ys;
If(x>=document.getElementById('content').offsetWidth-one.offsetWidth-20 || x<=0)
                                        {
                        xs=-1*xs;
              }
If(y>=document.getElementById('content').offsetHeight-one.offsetHeight-20 || y<=0)
                                        {
                   ys=-1*ys;
              }
                one.style.left=x;
              one.style.top=y;
          }
          dt=setInterval(scroll,100);
           one.onmouseover=function(){
                                                                                 ,,,,,,,,,,,,,,,,,,,,,,,,,,,            };
           one.onmouseout=function(){
          dt=setInterval(scroll,100);
           };
                                                                                         



Here’s a simple example.
Example 1

Copy code The code is as follows: function show(){ trace("I will show it every second");}
var sh;sh=setInterval(show,1000);
clearInterval(sh);



Example 2







Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template