1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 5 <title>javascript廣告代碼_兩側浮動</title> 6 <style type="text/css"> 7 body { height:10000px;} 8 </style> 9 </head>10 11 <body>12 <script>13 var ad_LR = { //javascript廣告代碼_兩側浮動14 speed : 200, //速度15 ad_left_gg : "<div id=\"ad_left_gg\" style='position:absolute; z-index:10; top:5px; left:5px; width:100px; height:400px;border:1px solid #ccc;'><a href='#' onclick=\"document.getElementById('ad_left_gg').style.display='none'; return false;\">關閉</a></div>", //左側16 ad_right_gg : "<div id=\"ad_right_gg\" style='position:absolute; z-index:10; top:5px; right:5px; width:100px; height:400px;border:1px solid #ccc;'><a href='#' onclick=\"document.getElementById('ad_right_gg').style.display = 'none'; return false;\">關閉</a></div>", //右側17 getScroll : function getScroll(){ //根據捲軸滾動18 var posY19 if (document.documentElement && document.documentElement.scrollTop) {20 posY = document.documentElement.scrollTop;21 } else if (document.body) {22 posY = document.body.scrollTop;23 }24 25 var top=window.screen.height>900 ? 5 : 5 ; //距離top的距離26 document.getElementById('ad_left_gg').style.top=(posY+top)+'px';27 document.getElementById('ad_right_gg').style.top=(posY+top)+'px';28 }29 }30 31 document.write (ad_LR.ad_left_gg, ad_LR.ad_right_gg);32 setInterval(ad_LR.getScroll, ad_LR.speed);33 34 </script>35 </body>36 </html>