admin管理员组文章数量:1403522
I'm currently trying to find a way to lock my header on the screen after most of it has scrolled off the top.
So, if for example, my header was 150 pixels high, is there anyway I could lock the bottom 15 pixels at the top of the screen after the top 135 pixels have scrolled off the top as the user scrolls down my page? So that no matter how long my page bees, there will always be the bottom 15 pixels of my header at the top of it.
I also need to reverse this when the user scrolls back up, so that the header can return to it's original state.
I've tried a dirty work around whereby having another header 15 pixels high with a "fixed" position layered behind my original header, so that when the full 150 pixel original one goes off the screen my new one appears out from behind it. This does work, but if the user catches it at mid point it looks disgraceful.
I have extremely limited knowledge of JavaScript and fear that may be where my answer lies.
I'm currently trying to find a way to lock my header on the screen after most of it has scrolled off the top.
So, if for example, my header was 150 pixels high, is there anyway I could lock the bottom 15 pixels at the top of the screen after the top 135 pixels have scrolled off the top as the user scrolls down my page? So that no matter how long my page bees, there will always be the bottom 15 pixels of my header at the top of it.
I also need to reverse this when the user scrolls back up, so that the header can return to it's original state.
I've tried a dirty work around whereby having another header 15 pixels high with a "fixed" position layered behind my original header, so that when the full 150 pixel original one goes off the screen my new one appears out from behind it. This does work, but if the user catches it at mid point it looks disgraceful.
I have extremely limited knowledge of JavaScript and fear that may be where my answer lies.
Share Improve this question asked Aug 27, 2011 at 16:16 FlickdrawFlickdraw 6837 gold badges14 silver badges25 bronze badges 01 Answer
Reset to default 8I am somewhat confused about what you want.. and from what youre saying.. I think you did about the same thing as I did.. but you didnt like it for some reason..
Anyhow.. if i got you right, this should work.
http://jsfiddle/5pJuJ/
Essentially there is element that is positioned fixed
which is behind the header and it is fixed
at the top and is therefore revealed once you scroll down.
Oh, right.. this doesnt work so well if theres like a gradient or something.. Was that the problem?
I did this to demonstrate the problem that I think youre having.. http://jsfiddle/5pJuJ/1/ ( which i think you shouldve provided... grr.. )
This seems like it does just what you want pretty well:
http://imakewebthings.github./jquery-waypoints/
http://imakewebthings.github./jquery-waypoints/sticky-elements/
本文标签: javascriptLock a div on the screen after so much of it has scrolled offStack Overflow
版权声明:本文标题:javascript - Lock a div on the screen after so much of it has scrolled off? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744364130a2602688.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论