返回顶部JS代码,不兼容谷歌浏览器!谁能帮我看看?_html/css_WEB-ITnose
回复讨论(解决方案)
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 scrolLeft = 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……
我这个怎么修改呢。。
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;
……
不行吖。。直接隐藏了 不显示了
引用 4 楼 的回复:
引用 3 楼 的回复:
JScript code
backTop = function (btnId) {
var btn = document.getElementById(btnId);
var d1 = document.documentElement;
var d2 = document.body;
……
不行吖。。直接隐藏了 ……
不返回首页了。
微信