只在html5里遇到,html4没事;拿出来聊聊,路过帮忙解答下!!!
不正常的
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>浮动广告</title>
<script type="text/javascript">
var advInitTop=0;
var closeInitTop=0;
function init(){
advInitTop=parseInt(document.getElementById("advLayer").style.top.slice(0, -2));
closeInitTop=parseInt(document.getElementById("closeLayer").style.top.slice(0, -2));
}
function move(){
//控制广告图片总位于页面顶端左边位置
document.getElementById("advLayer").style.top=advInitTop+document.body.scrollTop;
//控制关闭图片总位于页面顶端左边位置
document.getElementById("closeLayer").style.top=closeInitTop+document.body.scrollTop;
}
function closeMe(){
//关闭“关闭图片”所在的层
document.getElementById("closeLayer").style.display="none";
//关闭“广告图片”所在的层
document.getElementById("advLayer").style.display="none";
}
//当页面拖动滚动条时调用move()函数
window.οnscrοll=move;
</script>
</head>
<body onLoad="init()">
<div id="closeLayer" onClick="closeMe()" style="position:absolute; left:16px; top:200px;width:31px; height:31px; z-index:2;">
<img src="img/close.png" width="30" height="30"></div>
<p><img src="img/2.jpg" width="1000" height="4700"></p>
<div id="advLayer" style="position:absolute; left:16px; top:200px; width:250px; height:180px; z-index:1;"><a href="http://www.baidu.com">
<img src="img/timg.jpg" width="250" height="180" border="0"></a></div>
</body>
</html>
正常的(注释了<!doctype html>)
--<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>浮动广告</title>
<script type="text/javascript">
var advInitTop=0;
var closeInitTop=0;
function init(){
advInitTop=parseInt(document.getElementById("advLayer").style.top.slice(0, -2));
closeInitTop=parseInt(document.getElementById("closeLayer").style.top.slice(0, -2));
}
function move(){
//控制广告图片总位于页面顶端左边位置
document.getElementById("advLayer").style.top=advInitTop+document.body.scrollTop;
//控制关闭图片总位于页面顶端左边位置
document.getElementById("closeLayer").style.top=closeInitTop+document.body.scrollTop;
}
function closeMe(){
//关闭“关闭图片”所在的层
document.getElementById("closeLayer").style.display="none";
//关闭“广告图片”所在的层
document.getElementById("advLayer").style.display="none";
}
//当页面拖动滚动条时调用move()函数
window.οnscrοll=move;
</script>
</head>
<body onLoad="init()">
<div id="closeLayer" onClick="closeMe()" style="position:absolute; left:16px; top:200px;width:31px; height:31px; z-index:2;">
<img src="img/close.png" width="30" height="30"></div>
<p><img src="img/2.jpg" width="1000" height="4700"></p>
<div id="advLayer" style="position:absolute; left:16px; top:200px; width:250px; height:180px; z-index:1;"><a href="http://www.baidu.com">
<img src="img/timg.jpg" width="250" height="180" border="0"></a></div>
</body>
</html>