1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Document</title>6 <style>7 *{margin:0;padding:0;}8 #con{width:100px;Height:100px;background:Red;position:Absolute; Left:0;Top:100px;}9 #but{width:30px;Height:30px;}Ten One </style> A </Head> - <Body> - <inputID= "but"type= "button"value= "Go"> the <inputID= "BUT1"type= "button"value= "Stop"> - <DivID= "Con"></Div> - - <Script> + /*function as () { - alert (' AA '); + }; A setinterval (as,100)*/ at varCon=document.getElementById ('Con'); - var but=document.getElementById (' but'); - varBUT1=document.getElementById ('BUT1'); - varL=0; - varTimer=NULL, Time2=NULL, Time3=NULL; - But.onclick=function() { in clearinterval (timer); - //clear the Timer every time you click, and then execute it to prevent the page from being triggered by multiple timers . to Timer=SetInterval (function() { + L+=Ten; - Con.style.left=L+'px'; the }, -) * }; $ But1.onclick=function() {Panax Notoginseng clearinterval (timer); - }; the //time2=settimeout (function () { + //alert (' AA '); A //},1000) the //Timeout timer can be used as a delay effect. + </Script> - </Body> $ </HTML>View Code
Timer-block Move