0
我有2列布局,左边是固定边栏,右边是页面内容。我也有页脚。我希望我的固定边栏向右滚动到页面内容div末尾的坐标。限制固定div垂直滚动
但是,如果侧边栏的高度大于页面内容的高度,我需要自动为页面内容div分配新的高度。此代码适用于第一种情况(内容高于边栏),但第二种情况仅在我再次加载页面一次的情况下才有效(例如,当我从另一页面访问此类页面时,脚本不会分配新的高度,但是当我重新加载页面,它)
这里是代码:
$(window).load(function(){
var windw = this;
var contentHeight = $('#content').height(); // fetch Сontent div height
var sideHeight = $('.sidebar-nav-fixed').height(); // fetch sidebar div height
$.fn.followTo = function (pos) {
var $this = this,
$window = $(windw);
$window.scroll(function(e){
if ($window.scrollTop() >= pos) {
$this.css({
position: 'absolute',
top: pos
});
} else {
$this.css({
position: 'fixed',
top: 100
});
}
});
};
if (sideHeight > contentHeight) {
$('#content').css ({
height: contentHeight + (sideHeight - contentHeight)
}),
contentHeight = $('#content').height() // Assign a new height to page content div
}
$('.sidebar-nav-fixed').followTo(contentHeight - sideHeight);
});
我会很高兴,如果您有任何意见 谢谢!