跟随页面滚动的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;width: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>
<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;width: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>