(031)javascript_bom_advertise

 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=utf-8" />
 5     <title>BOM</title>
 6     <style type="text/css">
 7         #mydiv {
 8             width: 100px;
 9             height: 100px;
10             background: blue;
11             position: absolute;
12             right: 0;
13         }
14     </style>
15     <script type="text/javascript">
16 
17         window.onload = window.onresize = window.onscroll = function() {
18 
19             var myDivNode = document.getElementById("mydiv");
20             var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
21 
22             var t = (document.documentElement.clientHeight - myDivNode.offsetHeight) / 2;
23 
24             myDivNode.style.top = scrollTop + t + "px";
25 
26 
27         };
28         
29 
30     </script>
31 </head>
32 
33 <body style="height:2000px;">
34 
35     <div id="mydiv">
36     </div>
37 </body>
38 </html>

 

posted @ 2014-03-23 10:26  雪中飞雁  阅读(75)  评论(0)    收藏  举报