標籤:http get 相容 寫法 cti w3c tar script attribute
- <!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html>
- <head>
- <script type="text/javascript">
- var timer
- function scrolltop()
- {
- document.getElementById(‘scrollmenu‘).style.top=document.documentElement.scrollTop || document.body.scrollTop || 0;
- //相容寫法。頁面具有DTD時,使用document.documentElement.scrollTop;沒有指定DTD時使用document.body.scrollTop,所以用## || ## || 0 相容
- timer=setTimeout("scrolltop()",1) //1毫秒調用一次scrolltop()方法
- }
- function stoptimer()
- {
- clearTimeout(timer)
- }
- </script>
- </head>
-
- <body onload="scrolltop()" onunload="stoptimer()">
-
- <div id="scrollmenu" style="position:absolute;">
- <b>置頂菜單</b><br />
- <a href="###">導航一</a><br />
- <a href="###">導航二</a><br />
- <a href="###">導航三</a><br />
- <a href="###">導航四</a><br />
- </div>
-
- <p style="height:1000px">當頁面出現捲軸的時候,菜單依然置頂<br />預設為左上方置頂,當為id="scrollmenu"的style添加屬性right:0則右上方置頂</p>
-
-
- </body>
- </html>
通過js實現置頂方法