2016-05-30 Timer

Source: Internet
Author: User


<body><input id= "btn" type= "button" value= "buttons" ><div id= "div" ></div><script>varbtn= document.getElementById (' btn ')); varOdiv=document.getelementbyid ("div"); //var timer=null;Odiv.timer=NULL; Btn.onclick=function() {clearinterval (Odiv.timer);//prevent the animation in the execution process, artificial in the constant click button, constantly generate timers Odiv.timer=setinterval (function(){            varSpeed =getstyle (Odiv, ' left ', 50);//Odiv move to the right 50px            if(speed>900) { speed=900; } odiv.style.left=speed+ ' px ';//move 10px every 0.1s to the right            if(speed==900) {//Stop Movingclearinterval (Odiv.timer);            alert (speed); }        },200); }    functionGetStyle (obj,attr,step) {//why parseint (), because Obj.currentstyle[attr] got the 30px-->30        returnparseint (Obj.currentstyle?obj.currentstyle[attr]:getcomputedstyle (obj) [attr]) +step; }</script></body>

2016-05-30 Timer

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.