wordpress代码:添加反回顶部按钮
1、新建一个.js文件fanhui.js,并保存到自己网站目录http://www.phpfensi.com/wp-content/themes/twentyeleven/js代码如下:
- var isie6 = window.XMLHttpRequest ? false : true; function newtoponload() {
- var c = document.getElementByIdx_x_x(“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.getElementByIdx_x_x(“full”).onclick = function () { window.scrollTo(0, 0) };
2、将下面的代码复制到所用主题的footer.php文件,</body>标签之后、</html>标签之前的位置.
- <div id=”full” style=”width:50px; height:95px; position:fixed; left:49%; top:476px; margin-left:493px; z-index:100; text-align:center; cursor:pointer;”>
- <a><img src=”http:
- </div>
- <script src=”http:
- </script>
3、将上面的图片路径改为自己的返回顶部的图片地址,第二行红字改为自己fanhui.js所在目录,然后保存就可以了.