<script type="text/javascript"> backTop = function (btnId){ var btn = document.getElementById(btnId); var d = document.documentElement; window.onscroll = set; btn.onclick = function () { btn.style.display = "none"; window.onscroll = null; this.timer = setInterval(function () { d.scrollTop -= Math.ceil(d.scrollTop * 0.1); if (d.scrollTop == 0) clearInterval(btn.timer, window.onscroll = set); }, 10); }; function set() { btn.style.display = d.scrollTop ? 'block' : "none" } }; backTop('gotopbtn');
<a id="gotopbtn" style="position:fixed;width:12px;bottom:95px;right:195px;display:none;cursor:pointer;">返回顶部</a>
Chrome and Safari always use document.body.scrollTop, while IE and Firefox use document.body.scrollTop for quirks mode and document.documentElement.scrollTop for standard mode.
Your best bet may be something like:
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
var scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
Chrome and Safari always use document.body.scrollTop, while IE and Firefox use document.body.scrollTop for quirks mode and document.documentElement.scrollTop for standard mode.
Your best bet may be……
How do I modify this? .
backTop = function (btnId) { var btn = document.getElementById(btnId); var d1 = document.documentElement; var d2 = document.body; var d = d1.scrollTop + d2.scrollTop; window.onscroll = set; btn.onclick = function () { btn.style.display = "none"; window.onscroll = null; this.timer = setInterval(function () { d -= Math.ceil(d* 0.1); if (d == 0) clearInterval(btn.timer, window.onscroll = set); }, 10); }; function set() { btn.style.display = d ? 'block' : "none" } }; backTop('gotopbtn');
JScript code
backTop = function (btnId) {
var btn = document.getElementById(btnId);
var d1 = document.documentElement;
var d2 = document.body;
……
Not working. . Directly hidden and not displayed
Quote from the 4th floor’s reply:
Quote from the 3rd floor’s reply:
JScript code
backTop = function (btnId) {
var btn = document.getElementById(btnId);
var d1 = document.documentElement;
var d2 = document.body;
…
Not working. . Directly hidden...
Do not return to the home page.