Sport (i)

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Div move</title>    <style>Div{width:100px;Height:100px;Background-color:Green;position:Absolute; Left:0;Top:0;}input{Margin-top:120px;}    </style></Head><Body>    <DivID= "Div1"></Div>    <inputtype= "button"value= "Start Motion"onclick= "Startmove ()"></Body></HTML><Script>    var Time= NULL; functionStartmove () {varOdiv=document.getElementById ("Div1");        Clearinterval (time); time=SetInterval (function () {            varspend= 2; if(Odiv.offsetleft>=  -){//whether to reach the endclearinterval (time);//after reaching the finish line            }Else{oDiv.style.left=Odiv.offsetleft+spend+"px";//before you arrive            }        }, -); }</Script>

Thinking:

Will not stop, if () resolved;

Speed to take certain values when the time can not stop, pay attention to the condition ==300, the speed of 7 can not be stopped, resolved: Select the interval range;

When we reach 300, we also exercise. else solution;

Repeated clicks speed up, this is because each click, has opened a timer, so at the beginning of the event will be added clearinterval (time);

Sport (i)

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.