jquery, window.scroll, position a banner
I want to position a banner while scrolling:
The code is
$(window).scroll(function(){
offset = $(window).scrollTop()+80;
var h = $(window).height();
if(offset < 80 && offset < (h-800))
{
offset = 80;
}
$('#sidebar1').animate({top:offset}, 450);
});
The problem is the offset is dynamic开发者_StackOverflow and it changes while scrolling down, the banner goes beyond the window and while scrolling down it slides up slowly. I want a constant animation while scrolling up and down.
Is there a attribute like bottom instead of top, or is there an event other than scroll to achieve a constant scroll?
Old post I know but if anyone is looking for a solution see the jQuery stop method, code is written below.
$(window).scroll(function(){
offset = $(window).scrollTop()+80;
var h = $(window).height();
if(offset < 80 && offset < (h-800))
{
offset = 80;
}
$('#sidebar1').stop();
$('#sidebar1').animate({top:offset}, 450);
});
精彩评论