王尘宇王尘宇

研究百度干SEO做推广变成一个被互联网搞的人

分享一款我常用到的wordpress返回顶部的功用

我们用wordpress来做站都邑碰到页面内容比较长的时刻,高低拖沓页面着实贫苦,这时刻就需要一个wordpress返回顶部的功用了。网上相干教程也一大堆,又是js剧本啊,又是JQuery啊什么的,太贫苦了,现在天分享的是没有js挪用的,直接加个款式,再在底部加个代码就完事了,下面将此教程分享给人人!

1. 在style.css中增加以下代码

#gotop{width:38px;height:36px;position:fixed;bottom:25px;right:10px;top:auto;display:block;cursor:pointer;background: url(images/gotop.gif) no-repeat}*html #gotop{position:absolute;bottom:auto; top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));}

个中,bottom和right属性能够掌握按钮图片在右下角的位置,background属性能够修正返回顶部的图片。

2. 在footer.php中增加以下代码

<!-- 返回顶部 --><div style="display: none;" id="gotop"></div><script type='text/javascript'>backTop=function (btnId){        var btn=document.getElementById(btnId);        var d=document.documentElement;        var b=document.body;        window.onscroll=set;        btn.onclick=function (){            btn.style.display="none";            window.onscroll=null;            this.timer=setInterval(function(){                d.scrollTop-=Math.ceil((d.scrollTop+b.scrollTop)*0.1);                b.scrollTop-=Math.ceil((d.scrollTop+b.scrollTop)*0.1);                if((d.scrollTop+b.scrollTop)==0) clearInterval(btn.timer,window.onscroll=set);            },10);        };        function set(){btn.style.display=(d.scrollTop+b.scrollTop>100)?'block':"none"}    };    backTop('gotop');</script><!-- 返回顶部END -->

3. 增加返回顶部按钮图片 能够挑选本身喜好的

将图片保存到主题文件夹下的images里,图片名叫gotop.gif

相关文章

评论列表

发表评论:
验证码

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。