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=".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 ?
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./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 ?
Share Improve this question asked Jul 5, 2012 at 9:09 user1481850user1481850 2483 gold badges13 silver badges24 bronze badges2 Answers
Reset to default 3Your problem ist that your div
has the class
header, not the id
.
Try
<div id="header" style="position:fixed;top:100px;background-color:red">something</div>
$(document).ready(function(){
$('.header').scroll(function(){
$(this).css("top",Math.max(0,100-$(this).scrollTop()));
});
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744398751a4572278.html
评论列表(0条)