三步来实现为一个wordpress站点添加“返回顶部”按钮。
1、打开wordpress后台,选择“外观”–“编辑”–找到“footer.php”,在</body>之前加上下面这段代码:
代码如下 | 复制代码 |
<div id="full" style=" width:50px; height:95px; position:fixed; left:50%; top:420px; margin-left:493px; z-index:100; text-align:center; cursor:pointer;"> <a><img src="121008370928.png" border=0 alt="返回顶部"></a> </div> <script type="text/javascript">var isie6 = window.XMLHttpRequest ? false : true; function newtoponload() { var c = document.getElementById("full"); function b() { var a = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; if (a > 0) { if (isie6) { c.style.display = "none"; clearTimeout(window.show); window.show = setTimeout(function () { var d = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; if (d > 0) { c.style.display = "block"; c.style.top = (400 + d) + "px" } }, 300) } else { c.style.display = "block" } } else { c.style.display = "none" } } if (isie6) { c.style.position = "absolute" } window.onscroll = b; b() } if (window.attachEvent) { window.attachEvent("onload", newtoponload) } else { window.addEventListener("load", newtoponload, false) } document.getElementById("full").onclick = function () { window.scrollTo(0, 0) };</script> |
然后保存,删除缓存文件即可。
时间: 2024-09-18 12:41:53