set div position to fixed after scrolling 100px?
Posted
by
user1481850
on Stack Overflow
See other posts from Stack Overflow
or by user1481850
Published on 2012-07-05T09:09:38Z
Indexed on
2012/07/05
9:15 UTC
Read the original article
Hit count: 236
JavaScript
|jQuery
I tried to use the following function in order to set the div's position to 100 px from top after scrolling 100 px.
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(window).scroll(function(){
$("#header").css("top",Math.max(0,100-$(this).scrollTop()));
});
</script>
<div class="header" style="position:fixed;top:100px;background-color:red">something</div>
it is not working(the div stick to it's fixed position). it seems that the function is not relating to the div. what is my problem ?
© Stack Overflow or respective owner