<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>
<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>
本文介绍了一种使用JavaScript实现的网页元素动态定位及隐藏的方法。通过获取特定元素的位置信息,并结合页面滚动条的位置来实时调整元素位置,确保元素始终可见。同时提供了一个关闭按钮来隐藏这些元素。
402

被折叠的 条评论
为什么被折叠?



