div层一直处于页面中间

<html>
     <head>
         <title>测试</title>
     </head>
 <body>
fdfdfadf
 <table width="200" height="3600" border="1">
<tr>
<td>qqxcxcxzc .dfd...,dsfsd,dfds</td>
</tr>
</table>
 <div id="a" style="POSITION: absolute;border:1px solid red;">11dsfsdf23</div>
 <script>
 function $(id){
         return document.getElementById(id);
 }
     
 function getPageTopScroll(){ 
 var yScroll;
 if (self.pageYOffset) {
 yScroll = self.pageYOffset;
 } else if (document.documentElement && document.documentElement.scrollTop){
 yScroll = document.documentElement.scrollTop;
 } else if (document.body) {
 yScroll = document.body.scrollTop;
 }
 return yScroll;
 }
 
 window.onload=function div(){
   
               var aa=getPageTopScroll();                              
              $("a").style.top=aa+document.body.clientHeight/2;
            setTimeout("div()",100)
             }
 </script>
 </body>
 </html>

作者:沐雪
文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。本文版权归作者和博客园共有,如需转载恳请注明。
如果您觉得阅读这篇博客让你有所收获,请点击右下方【推荐】
找一找教程网-随时随地学软件编程 http://www.zyiz.net/

原文地址:https://www.cnblogs.com/puzi0315/p/2658295.html