我正在使用一个粘性条,当我滚动到它时我想要修复它,当它触及页脚时它变成绝对位置
if ($('.sidebar').length ) {
var elementPosition = $('.sidebar').offset();
var footerOffset = $(document).height() - $('footer').height() - $('.sidebar').height();
$(window).scroll(function(){
if($(window).scrollTop() > elementPosition.top){
if ($(window).scrollTop() < footerOffset) {
$('.sidebar').css('position','fixed').css('top','0px').css('margin','0 0 0 690px');
} else{
$('.sidebar').css('position','absolute').css('top',footerOffset + 'px').css('margin','0 0 0 690px');
}
} else {
$('.sidebar').css('position','relative').css('top','inherit').css('margin','0 0 0 20px');
}
});
};
但它有时可以正常工作,有时它无法计算footerOffset var并使侧边栏超过页脚
你可以查一下吗 http://engez-eg.com/aboodnour/screenshots/featured