/*** Return to the top of the page * @ Param acceleration * @ Param time interval (MS) **/function gotop (acceleration, time ){
// Window. scrollto (0, 0); // you can directly use this function if you do not need the animation effect.
Acceleration = acceleration | 0.1; time = Time | 16; var X1 = 0; var Y1 = 0; var X2 = 0; var y2 = 0; var X3 = 0; vaR Y3 = 0; If (document.doc umentelement) {x1 = document.doc umentelement. scrollleft | 0; Y1 = document.doc umentelement. scrolltop | 0;} If (document. body) {X2 = document. body. scrollleft | 0; y2 = document. body. scrolltop | 0;} var X3 = Window. scrollx | 0; var Y3 = Window. scrolly | 0; // horizontal distance from the scroll bar to the top of the page var x = math. max (x1, math. max (X2, X3); // vertical distance from the scroll bar to the top of the page var y = math. max (Y1, math. max (Y2, Y3); // rolling distance = current distance/speed, because the smaller the distance, the speed is greater than 1, therefore, the rolling distance will be smaller and smaller. var speed = 1 + acceleration; window. scrollto (math. floor (x/speed), math. floor (y/speed); // if the distance is not zero, continue to call the iteration function if (x> 0 | Y> 0) {var invokefunction = "gotop (" + acceleration + "," + time + ")"; window. setTimeout (invokefunction, time );}}
Document.doc umentelement. scrolltop, document. Body. scrolltop, window. scrolly are actually the same, but they only play a role in some browsers. You can debug which browsers play a role.
<a href="#" onclick="goTop();return false;">TOP</a>