Multiple codes that return the top and multiple codes that return the top
Code 1:
$ ("# Back-to-top"). click (function (){
$ ('Body, html '). animate ({
ScrollTop: 0
},1000 );
Return false;
});
Code 2:
<! DOCTYPE html>
<Html>
<Head lang = "en">
<Meta charset = "UTF-8">
<Title> </title>
</Head>
<Body style = "height: 6000px; position: relative;">
<A href = "javascript:;" style = "position: absolute; right: 0; bottom: 0;" id = "btn"> return to the top </a>
<Script type = "text/javascript">
Window. onload = function ()
{
Var btn = document. getElementById ("btn ");
Var scrolldelay;
Var iNow = 0;
Var top = document. body. scrollTop | document.doc umentElement. scrollTop;
Window. onscroll = function ()
{
Top = document. body. scrollTop | document.doc umentElement. scrollTop;
If (top <= 0)
{
ClearInterval (scrolldelay );
}
};
Btn. onclick = function ()
{
Scrolldelay = setInterval (pageScroll, 60 );
Function pageScroll (){
INow ++ = 200;
Window. scrollBy (0,-iNow );
}
};
}
</Script>
</Body>
</Html>