国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Wordpress > 正文

WordPress增加返回頂部效果代碼

2024-09-07 00:49:55
字體:
來源:轉載
供稿:網友

返回頂部效果不是WordPress自帶的功能了,這是一款js或jquery的效果,下面我給大家介紹在WordPress中增加反回頂部的效果代碼,有需要了解的朋友可參考.

第一步:在下面主題文件footer.php底下加上這段代碼:

  1. <script src="top.js" type="text/javascript" charset="utf-8"></script > 
  2. <div id="scroll"><a href="javascript:void(0)" onclick="goto_top()" title="返回頂部">TOP</a></div> 

top.js代碼如下:

  1. //<![CDATA[ 
  2. var goto_top_type = -1; 
  3. var goto_top_itv = 0; 
  4. function goto_top_timer() 
  5. var y = goto_top_type == 1 ? document.documentElement.scrollTop : document.body.scrollTop; 
  6. var moveby = 15; 
  7. y -= Math.ceil(y * moveby / 100); 
  8. if (y < 0) { 
  9. y = 0; 
  10. if (goto_top_type == 1) { 
  11. document.documentElement.scrollTop = y; 
  12. else { 
  13. document.body.scrollTop = y; 
  14. if (y == 0) { 
  15. clearInterval(goto_top_itv); 
  16. goto_top_itv = 0; 
  17. function goto_top() 
  18. if (goto_top_itv == 0) { 
  19. if (document.documentElement && document.documentElement.scrollTop) { 
  20. goto_top_type = 1; 
  21. else if (document.body && document.body.scrollTop) { 
  22. goto_top_type = 2; 
  23. else { 
  24. goto_top_type = 0; 
  25. if (goto_top_type > 0) { 
  26. goto_top_itv = setInterval('goto_top_timer()', 50); 
  27. //]]> 

第二步:在主題文件style.css文件中加入以下樣式:

  1. /*返回頂部*/ 
  2. #scroll {display:blockwidth:30pxmargin-right:-380px
  3. position:fixed
  4. right:50%
  5. top:90%
  6. _margin-right:-507px
  7. _position:absolute
  8. _margin-top:30px
  9. _top:expression(eval(document.documentElement.scrollTop)); 
  10. #scroll a { 
  11. display:block
  12. float:right
  13. padding:9px 5px
  14. cursorpointer
  15. background-color:#444
  16. color:#fff
  17. border-radius:5px
  18. text-decorationnone
  19. font-weight:bold
  20. #scroll a:hover { 
  21. background-color:#333
  22. color:#669900
  23. text-decorationnone
  24. font-weight:bold

這樣我們再清除緩存是不是就可以看到有個返回頂部的效果按鈕了,這樣你的WordPress博客中的所有頁面都會有返回頂部效果了.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 夏邑县| 张家川| 和平县| 苏尼特右旗| 会理县| 静宁县| 巧家县| 德清县| 澄迈县| 龙胜| 安陆市| 大同县| 中江县| 喜德县| 息烽县| 资源县| 中山市| 修武县| 金乡县| 全州县| 青冈县| 阿合奇县| 抚宁县| 东乡| 固始县| 凤冈县| 江都市| 大埔区| 洱源县| 阿尔山市| 报价| 塔河县| 肇东市| 巫溪县| 临潭县| 囊谦县| 丰台区| 宜宾市| 灵璧县| 库车县| 沂南县|