请在下面找到修复DIV元素位置的示例HTML代码。现在,我需要能够在开始滚动时将“setupBar”移动到(0,0)位置(或基于滚动位置的位置),然后将其冻结。在滚动页面时移动/修复DIV元素顶部
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div id="mainBar" style="height:20px; border:1px solid red"></div>
<div id="setupBar" style="position:fixed; border:1px solid blue; height:20px; width:100%"></div>
<div style="height:1500px; background-color:#CCCCCC"></div>
</body>
</html>
PS:我在寻找一个JS的解决方案,可以移动DIV向上或向下取决于当前的滚动位置(不是CSS修复):)
我很好奇你为什么不想只用一个位置:fixed; CSS样式定义来做到这一点?这似乎是一个比js更清洁的解决方案。 – Evert 2012-01-09 12:09:16
重复:http://stackoverflow.com/q/7735002/681807 – 2012-01-09 12:09:19
CSS是更好的这个目的 – Bernat 2012-01-09 12:37:17