怎么让一个div元素总是停留在窗口的上方,即使滑块被拉动?
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!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>
<title>无标题页</title>
<script type="text/javascript" language="javascript">
window.onscroll = function()
{
var oTextbox = document.getElementById("txt1");
oTextbox.value += "\nscroll is at "+document.body.scrollLeft+" horizontally and "+document.body.scroolTop +" vertically.";
var oWatermark = document.getElementById("divWatermark");
oWatermark.style.top = document.body.scrollTop;//怎么不起作用?
}
</script>
</head>
<body>
<p>Use your mouse to click and double click the red square.</p>
<p><textarea rows="15" cols="50px" id="txt1"></textarea></p>
<div id="divWatermark" style="position:absolute;top:0px;right:0px;color:#cccccc;width:150px;height:30px;background-color:Navy">Watermark</div>
<p>Line 1</p>
<p>Line 2</p>
<p>Line 3</p>
<p>Line 4</p>
<p>Line 5</p>
<p>Line 6</p>
<p>Line 7</p>
<p>Line 8</p>
<p>Line 9</p>
<p>Line 10</p>
<p>Line 11</p>
<p>Line 12</p>
</body>
</html> 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script type="text/javascript" language="javascript">
window.onscroll = function()
{
var oTextbox = document.getElementById("txt1");
oTextbox.value += "\nscroll is at "+document.body.scrollLeft+" horizontally and "+document.body.scroolTop +" vertically.";
var oWatermark = document.getElementById("divWatermark");
oWatermark.style.top = document.body.scrollTop;//怎么不起作用?
}
</script>
</head>
<body>
<p>Use your mouse to click and double click the red square.</p>
<p><textarea rows="15" cols="50px" id="txt1"></textarea></p>
<div id="divWatermark" style="position:absolute;top:0px;right:0px;color:#cccccc;width:150px;height:30px;background-color:Navy">Watermark</div>
<p>Line 1</p>
<p>Line 2</p>
<p>Line 3</p>
<p>Line 4</p>
<p>Line 5</p>
<p>Line 6</p>
<p>Line 7</p>
<p>Line 8</p>
<p>Line 9</p>
<p>Line 10</p>
<p>Line 11</p>
<p>Line 12</p>
</body>
</html> 展开
展开全部
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
var picTop=0;
function move(){
document.getElementById("Layer").style.pixelTop=picTop+document.body.scrollTop;
}
window.onscroll=move;
</script>
<body>
<div id="Layer"style="position:absolute; left:16px; top:0px; width:333px; height:100px; z-index:1;">
<img src="" width="333" height="100" alt="" style="background-color: #0099CC" /></div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
var picTop=0;
function move(){
document.getElementById("Layer").style.pixelTop=picTop+document.body.scrollTop;
}
window.onscroll=move;
</script>
<body>
<div id="Layer"style="position:absolute; left:16px; top:0px; width:333px; height:100px; z-index:1;">
<img src="" width="333" height="100" alt="" style="background-color: #0099CC" /></div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询