When browsing the Web page, you should often see a floating stuff [back to the top] in the lower right corner. This article also needs to be implemented using js. If you are interested, refer to the following, I hope this will help you see many floating items [back to the top] in the bottom right corner of the page. If they do not exist at the beginning, they will appear as soon as they move the scroll bar, it disappears at the top.
For example:
The javascript code is as follows:
The Code is as follows:
Function goTop (){
Var _ btn = document. getElementById ("goTop ");
If (document.doc umentElement & document.doc umentElement. scrollTop ){
Var _ con = document.doc umentElement;
} Else if (document. body ){
Var _ con = document. body;
}
Window. onscroll = set;
_ Btn. style. left = document.doc umentElement. scrollWidth/2 + 500 + "px ";
_ Btn. onclick = function (){
_ Btn. style. display = "none ";
Window. onscroll = null;
This. timer = setInterval (function (){
_ Con. scrollTop-= Math. ceil (_ con. scrollTop * 0.3 );
If (_ con. scrollTop = 0) clearInterval (_ btn. timer, window. onscroll = set );
}, 10 );
};
Function set (){
_ Btn. style. display = _ con. scrollTop? 'Block': "none ";
}
};
Document. write ("
Return
Back
Top
Department
");
Window. onscroll = goTop;