在WordPress中添加返回頂部的功能

1. 在style.css中添加如下代碼

/**返回頂部**/
#gotop{
width:45px;
height:45px;
position:fixed;
bottom:25px;
right:125px;
top:auto;
display:block;
cursor:pointer;
background: url(images/top.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)));
}

css-300x54.png

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. (){
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 –>

footer-300x117.png

3. 添加返回頂部按鈕圖片

把返回頂部按鈕,上傳到主題目錄的images目錄下:

top.gif

本文固定鏈接: http://www.test-life.org/?p=718 | 軟件開發測試之路-Test Space


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章