1
当前我的侧边栏比浏览器窗口更长,它会粘贴到屏幕的底部。当页脚出现时,我需要它停止粘贴到屏幕的底部,所以它不会覆盖页脚。解除粘贴到屏幕底部的div
我也想让我的标头贴到屏幕的顶部,但没有侧栏覆盖它。应该注意的是,我已经尝试过使用jQuery的hcsticky插件,但是我根本无法完成它。
$(window).load(function(){
var $sidebar = $("#sidebar"),
$thefoot = $("#thefoot"),
$window = $(window),
offset = $sidebar.offset(),
sbBottom = Math.abs($window.height() - (offset.top + $sidebar.height())),
prevScrollTop = 0;
$window.scroll(function() {
if (prevScrollTop < $window.scrollTop()) {
$sidebar.removeClass('fixedTop');
if ($window.scrollTop() > (sbBottom + 12)) {
$sidebar.addClass('fixedBtm');
} else {
$sidebar.removeClass('fixedBtm');
}
} else {
$sidebar.removeClass('fixedBtm');
if ($window.scrollTop() > sbBottom) {
$sidebar.addClass('fixedTop');
} else {
$sidebar.removeClass('fixedTop');
}
} });
});
#sidebar {
width: 300px;
margin-bottom: 10px;
overflow: hidden;
margin: 0 auto;
float: left;
clear: right;
}
.fixedBtm {
margin-left: 660px !important;
position: fixed;
bottom: 0;
}
.fixedTop {
margin-left: 660px !important;
position: fixed;
bottom: 0;
}
.footBtm {
bottom: 350px;
}
#thefoot {
background-color: #5774F2;
clear: both;
background-color: #ffffff;
background-repeat: no-repeat;
background-position: center;
background-image: url("../images/footer.png");
height: 340px;
width: 100%;
}
我会尝试进一步解释,侧边栏是动态的,所以我不能在javascript中使用像素值,使页面出现时停止粘贴到浏览器窗口的底部。侧边栏有一个固定的位置,所以我不能只漂浮它。 – Trikucian