This article describes the use of absolute positioning of JS to achieve the effect of back to the top. Share it for your reference, as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Absolute Positioning Back to Top Button</title><style type="text/css">body{margin:0px;padding:0px;height:2500px;background:#6f0024;}#div1{width:120px;height:34px;right:4px;bottom:5px;cursor:pointer;background:url(images/ToTop.png) no-repeat;position:fixed;_position:absolute;display:none;}</style><script type="text/javascript">//absolute positioning hide display function getScroll(id){ var obj = document.getElementById(id); var timer = null; positionFixed(obj); if(obj){ obj.style.display = 'none'; window.onscroll=function(){ getScrollTop() > 0 ? obj.style.display = "block" : obj.style.display = "none"; } obj.onclick=function(){ var timer = setInterval(sMove,10); function sMove(){ setScrollTop(getScrollTop() / 1.5); if(getScrollTop() < 1)clearInterval(timer); } } } }}//Judge IE6 function positionFixed(obj){ var iE6 = !-[1,] && !window.XMLHttpRequest; if(obj){ var top = obj.offsetTop; if(iE6){ document.documentElement.style.textOverflow = "ellipsis"; obj.style.position = "absolute"; obj.style.setExpression("top", "eval(documentElement.scrollTop + " + top + ') + "px"'); } }}//Get the scrollbar Topfunction getScrollTop(){ return document.documentElement.scrollTop || document.body.scrollTop;}//Back to top function setScrollTop(value){ document.documentElement.scrollTop = value; document.body.scrollTop = value;}window.onload = function(){ getScroll('div1');};</script></head><body><div id="div1"></div></body></html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.