zoukankan      html  css  js  c++  java
  • 跟随页面滚动的div(firefox,ie,chrome),兼给setTimeout传递参数的方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
       body{height:3000px;background:url(http://www.baidu.com/img/baidu_logo.gif) repeat-y;}
       /*滚动的div必须初始化top,left,height,width的值*/
       #Cs_Ox37{position:absolute;top:0px;left:0px;height:110px;286px;background:url(http://www.google.cn/intl/zh-CN/images/logo_cn.gif) no-repeat;}
    </style>
    </head>
    <body>
    <div id="Cs_Ox37">
    </div>
    </body>
    </html>
    <script language="javascript" type="text/javascript">
       //随页面滚动的div
       function scrollDiv(e){
           var scrollTop=window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
           var top=parseInt(e.style.top);
           if(scrollTop!=top){
               e.style.top=scrollTop+'px'
           }
           //以下是如何给setTimeout传递参数的方法(js遇到无法传参时都可考虑用此方法)
           var func=function(div){return function(){scrollDiv(div)}}(e);
           window.setTimeout(func,300);
       }  
       window.onload=function(){
           scrollDiv(document.getElementById('Cs_Ox37'));
       }
    </script>
  • 相关阅读:
    sqlserver 中的 substring函数(转)
    C#二个相减怎么获得天数,就是比如201225 与201231之间相差的天数
    C++文件添加到项目中
    VS2008动态链接库(DLL)的创建与导入
    美剧字幕绿箭侠第1季第7集
    C++中#define用法
    C++头文件的重复引用
    visual studio中解决方案是什么
    NewWords/300400
    指针
  • 原文地址:https://www.cnblogs.com/superfeeling/p/1997767.html
Copyright © 2011-2022 走看看