<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title></title>
 <style type="text/css">
  #ad{
   position:absolute;
   top:120px;
   left:50px;
   width:100px;
   height:200px;
   background-color:#333;
   color:#fff;
  }
 </style>
 
 <script type="text/javascript">
  window.onload=init;
  window.onscroll=go;
  var oldTop;
  
  function init(){
  
   var ad=document.getElementById("ad");
   
   //取对象原始的top值
   if(window.getComputedStyle){
    oldTop= parseInt( window.getComputedStyle(ad,null).top );
   }else{
    //IE
    oldTop= parseInt(ad.currentStyle.top);
   }
  }
  function go(){
   //浏览器滚动的距离
   var top=document.documentElement.scrollTop;
   
   document.getElementById("ad").style.top= parseInt(top)+oldTop +"px";
   
  }
  //关闭广告
  function closeAd(){
   var ad=document.getElementById("ad");
   ad.parentNode.removeChild(ad);
  }
  
 </script>
</head>
<body>
 <div >sss</div>
 
</body>
</html>

相关文章:

  • 2021-11-12
  • 2021-09-28
  • 2022-12-23
  • 2021-10-26
  • 2021-05-30
  • 2022-12-23
  • 2021-12-08
  • 2021-09-07
猜你喜欢
  • 2021-04-21
  • 2022-12-23
  • 2022-01-05
  • 2021-11-27
  • 2022-12-23
  • 2021-07-08
  • 2021-10-19
相关资源
相似解决方案