图片固定位置的问题,为什么在火狐中图片不随鼠标滚动,而在ie中却实现不了?
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content...
<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">
#adver{
position:absolute;
left:50px;
top:30px;
z-index:2;
}
h1{
height:50px;
}
</style>
<script type="text/javascript">
var adverTop; //层距页面顶端距离
var adverLeft;
var adverObject; //层对象
function inix(){
adverObject=document.getElementById("adver"); //获得层对象
if(adverObject.currentStyle){
adverTop=parseInt(adverObject.currentStyle.top);
adverLeft=parseInt(adverObject.currentStyle.left);
}
else{
adverTop=parseInt(document.defaultView.getComputedStyle(adverObject,null).top);
adverLeft=parseInt(document.defaultView.getComputedStyle(adverObject,null).left);
}
}
function move(){
adverObject.style.top=adverTop+parseInt(document.documentElement.scrollTop)+"px";
adverObject.style.left=adverLeft+parseInt(document.documentElement.scrollLeft)+"px";
}
window.onload=inix;
window.onscroll=move;
</script>
</head>
<body>
<div id="adver"><img src="images/pic_01.jpg" /> </div>
<div id="main">
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
</div>
</body>
</html> 展开
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#adver{
position:absolute;
left:50px;
top:30px;
z-index:2;
}
h1{
height:50px;
}
</style>
<script type="text/javascript">
var adverTop; //层距页面顶端距离
var adverLeft;
var adverObject; //层对象
function inix(){
adverObject=document.getElementById("adver"); //获得层对象
if(adverObject.currentStyle){
adverTop=parseInt(adverObject.currentStyle.top);
adverLeft=parseInt(adverObject.currentStyle.left);
}
else{
adverTop=parseInt(document.defaultView.getComputedStyle(adverObject,null).top);
adverLeft=parseInt(document.defaultView.getComputedStyle(adverObject,null).left);
}
}
function move(){
adverObject.style.top=adverTop+parseInt(document.documentElement.scrollTop)+"px";
adverObject.style.left=adverLeft+parseInt(document.documentElement.scrollLeft)+"px";
}
window.onload=inix;
window.onscroll=move;
</script>
</head>
<body>
<div id="adver"><img src="images/pic_01.jpg" /> </div>
<div id="main">
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
<h1>dasd</h1><br />
</div>
</body>
</html> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询