zoukankan      html  css  js  c++  java
  • Javascript 广告定位

    <!DOCTYPE html>
    <html>
    <head>
     <meta charset="utf-8">
     <title></title>
     <style type="text/css">
      #ad{
       position:absolute;
       top:120px;
       left:50px;
       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 id="ad"><a href="javascript:;" onclick="closeAd()">X</a><a class="close" onclick="this.parentNode.parentNode.removeChild(this.parentNode)">close</a>广告</div>
     <div style="height:5000px;">sss</div>
     
    </body>
    </html>

  • 相关阅读:
    poj2661Factstone Benchmark
    完整的微信接口类 (转)
    位运算(转载)
    PHP学习笔记之数组游标操作
    MYSQL数据库数据拆分之分库分表总结 (转)
    webservice使用
    MySQL索引类型总结和使用技巧以及注意事项 (转)
    PHP empty、isset、isnull的区别
    myisam和innodb的区别
    看看PHP迭代器的内部执行过程(转)
  • 原文地址:https://www.cnblogs.com/wicub/p/3123054.html
Copyright © 2011-2022 走看看