我正在使用以下 jQuery 函数:
$(document).ready(function () {
var top = $('.aside').offset().top - parseFloat($('.aside').css('marginTop').replace(/auto/, 0));
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that's below the form
if (y >= top) {
// if so, ad the fixed class
$('.aside').addClass('fixed');
} else {
// otherwise remove it
$('.aside').removeClass('fixed');
}
});
});
现在我希望固定的 DIV (.aside) 停止在特定的 DIV 处。
请看我的CSS。它是一个 2 列布局,左侧有一个主 .content 列,右侧有一个 .aside 栏。我希望 .aside 栏滚动到 .content 列的末尾。至少当 .aside 栏到达页脚时。希望你能理解我=)
.content {
float:left;
}
.container.sticky .row {
position: relative;
background: #fff;
}
.aside-wrapper { /* required to avoid jumping */
left: 640px;
position: absolute;
}
.aside {
position: absolute;
top: 0;
}
.aside.fixed {
position: fixed;
top: 0;
}
我怎样才能做到这一点?