图片随滚动条滚动的代码

来源:互联网 发布:易通网络vpn加速器 编辑:程序博客网 时间:2024/06/09 19:57
<!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>


<script type="text/javascript">
window.onload=initial;
window.onscroll=move;
var advObj;
var advTop;
var advLeft;

function initial(){
advObj=document.getElementById("adver");
if(advObj.currentStyle){
advTop=parseInt(advObj.currentStyle.top);
advLeft=parseInt(advObj.currentStyle.left);
}else{

advTop=parseInt(document.defaultView.getComputedStyle(advObj,null).top);
advLeft=parseInt(document.defaultView.getComputedStyle(advObj,null).left);
}
}
function move(){
advObj.style.top=advTop+parseInt(document.documentElement.scrollTop)+"px";//猎豹浏览器不适用

//advObj.style.top=advTop+parseInt(window.pageYOffset)+"px";

advObj.style.left=advLeft+parseInt(document.documentElement.scrollLeft)+"px";
}
</script>
</head>
<body>
<div id="adver" style="position:absolute;z-index:1;top:420px;">
<img src="d.png" width="275" height="261" />
</div>
<div style="width:900px;height:1500px;background-color:#CCC;margin-left:150px;">

文本....

</div>
</body>


</html>
0 0
原创粉丝点击