0
我现在已经让#filter
(我的侧边栏白色选择列表)变成fixed
当它到达顶部并且在滚动期间停留在那里直到它到达脚版本。固定在滚动条上的位置在到达顶部之前就开始了(顶部div)
我的问题是,我在位于fixed
头部<div>
箱, 所以#filter
不会从固定到页面的顶部。这意味着我在抓取位置固定前获得抓取。 如何才能在达到最高点之前将其变为fixed
40px?
$(function() {
var top = $('#filter').offset().top,
footTop = $('#outside_footer_wrapper').offset().top,
maxY = footTop - $('#filter').outerHeight();
console.log(top , footTop, maxY);
$(window).scroll(function(evt) {
var y = $(this).scrollTop();
console.log(y);
if (y > top) {
console.log('mayor');
$('#filter').addClass('fixed').removeAttr('style');
if (y > maxY-130){
var min = y - maxY + 130;
console.log('mayor y menor', min);
$('#filter').css('top','-'+min+'px');
}
} else {
$('#filter').removeClass('fixed');
}
});
});
你可以把一个初始值(20像素从顶部)? –
然后只加20顶部变量...所以在$(窗口).scroll – Craftein
之前的任何地方当我使用你写的变化,所以它稳定在我不希望它做的脚。 –