通過js實現置頂方法

來源:互聯網
上載者:User

標籤:http   get   相容   寫法   cti   w3c   tar   script   attribute   

  1. <!DOCTYPE html  
  2. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4. <html>  
  5. <head>  
  6. <script type="text/javascript">  
  7. var timer  
  8. function scrolltop()  
  9. {  
  10. document.getElementById(‘scrollmenu‘).style.top=document.documentElement.scrollTop || document.body.scrollTop || 0;  
  11. //相容寫法。頁面具有DTD時,使用document.documentElement.scrollTop;沒有指定DTD時使用document.body.scrollTop,所以用## || ## || 0 相容  
  12. timer=setTimeout("scrolltop()",1) //1毫秒調用一次scrolltop()方法  
  13. }  
  14. function stoptimer()  
  15. {  
  16. clearTimeout(timer)  
  17. }  
  18. </script>  
  19. </head>  
  20.   
  21. <body onload="scrolltop()" onunload="stoptimer()">  
  22.   
  23. <div id="scrollmenu" style="position:absolute;">  
  24. <b>置頂菜單</b><br />  
  25. <a href="###">導航一</a><br />  
  26. <a href="###">導航二</a><br />  
  27. <a href="###">導航三</a><br />  
  28. <a href="###">導航四</a><br />  
  29. </div>  
  30.   
  31. <p style="height:1000px">當頁面出現捲軸的時候,菜單依然置頂<br />預設為左上方置頂,當為id="scrollmenu"的style添加屬性right:0則右上方置頂</p>  
  32.   
  33.   
  34. </body>  
  35. </html>  

通過js實現置頂方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.