Rumah > Artikel > hujung hadapan web > 返回顶部JS代码,不兼容谷歌浏览器!谁能帮我看看?_html/css_WEB-ITnose
<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 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;
……
不行吖。。直接隐藏了 ……
不返回首页了。
nbsp;HTML>
nbsp;HTML>
nbsp;HTML>