Return top with motion: When the scroll bar is scrolling, scroll the mouse wheel, should let the scroll bar to stop scrolling, clear out the timer. The following method, B, is the method of clearing out
1 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en"2 "Http://www.w3.org/TR/html4/strict.dtd">3 4 <HTMLxmlns= "http://www.w3.org/1999/xhtml"Lang= "en">5 <Head>6 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />7 <title>6. Return to top with movement</title>8 <Metaname= "Author"content= "Administrator" />9 <!--date:2014-12-12 -Ten <style> One #goTop{width:50px;Height:50px;Border-radius:5px;background:#006666;position:fixed; Right:10px;Bottom:10px;text-align:Center;Line-height:50px;} A </style> - <Script> - /** Scroll strip movement back to top the * The value of the movement is the distance from the top of the document, and the value is obtained within the timer . - * Speed is the target point (0-current scrolltop)/8 - * When scrolling distance is assigned, you need to connect and so on: - * document.documentelement.scrolltop=document.body.scrolltop= icur +ispeed**/ + window.onload=function(){ - varOdiv=document.getElementById ('Gotop'); + varTimer=NULL; A varb=1; at functionsettop () { - varscrolltop=Document.documentElement.scrollTop||Document.body.scrollTop; - } - - Window.onscroll=function(){ - in if(b!=1 ){ //if b=1, then B is triggered by the timer, if not equal, is triggered by other events, this time to turn off the timer - clearinterval (timer); to } + b=2 - } the * Odiv.onclick=function(){ $ clearinterval (timer)Panax Notoginseng Timer=SetInterval (function(){ - varIcur=Document.documentElement.scrollTop||Document.body.scrollTop; the varIspeed=Math.floor ((0 -icur)/8); + A Document.documentElement.scrollTop=Document.body.scrollTop=Icur+Ispeed; the b=1; + - if(Icur== 0){ $ clearinterval (timer) $ } - - }, -) the } - }Wuyi </Script> the </Head> - <Bodystyle= "height:2000px;"> Wu <DivID= "Gotop">Top</Div> - </Body> About </HTML>
View Code
JS Belt movement back to top small case