日期:2014-05-16  浏览次数:20311 次

onscroll如何实现层随页面滚动?
如题.给个例子.谢谢

------解决方案--------------------
<html>
<head>
<script language = "javascript">
var checks = 0;
var GB =0;
function openwindow()
{
checks = document.getElementById("player").style.pixelTop;
GB = document.getElementById("myplay").style.pixelTop;
}
function move()
{
document.getElementById("player").style.pixelTop = checks + document.body.scrollTop;
document.getElementById("myplay").style.pixelTop = GB + document.body.scrollTop;
}
function guna()
{
document.getElementById("myplay").style.display = "none";
document.getElementById("player").style.display = "none";
}
window.onscroll = move;
</script>
</head>
<body onload = "openwindow()">
<div id = "play" style = "position:absolute;height:2000px;width:990px;background-color:orange;z-index:1"></div>
<div id = "player" style = "position:absolute;height:100px;width:100px;left:900px;top:100px;background-color:blue;z-index:2"></div>
<div id = "myplay" style = "position:absolute;heigth:20px;width:40px;left:970px;top:80px;z-index:3" onclick = "guna()"><font size = 3 color = red><a href = "#">关闭</a></font></div>
</body>
</html>