admin管理员组文章数量:1415673
Case example: I have a long list of items, and when I put my mouse over this div changes to that picture of that item. No matter where you scroll to, the div remains in a fixed position.
Sort of like a frame.
Case example: I have a long list of items, and when I put my mouse over this div changes to that picture of that item. No matter where you scroll to, the div remains in a fixed position.
Sort of like a frame.
Share Improve this question asked Apr 17, 2010 at 8:41 fivetwentysixfivetwentysix 7,4959 gold badges42 silver badges59 bronze badges5 Answers
Reset to default 3Use the CSS property position:fixed
.
Example: <div id="items" style="position: fixed; top: 20px; right: 20px">Hello there!</div>
the div remains in a fixed position.
position: fixed
? Test it here.
For newer browsers you can use position:fixed
to make an element follow the window when you scroll.
If you need to be patible with older browsers, you would need a Javascript that gets the scroll offset from the window and changes the coordinates of an absolutely positioned element.
Absolute positioning:
<body>
<div style="position: absolute; top: 0; right: 0; width: 100px; height: 100px;">
</div>
</body>
Are you asking about div in fixed position? If you want to this the div by css itself, you can use the paramater like
height:0px;
left:0px;
position:absolute;
top:0px;
width:0px;
z-index:1;
本文标签:
版权声明:本文标题:javascript - How do I make a div that stays in a fixed position regardless of where you are on the page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745213509a2648026.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论