滑动到底部 固定侧边栏

J_BdSide是滑动侧边栏id选择器

<script>
$(window).scroll(function() {
var windowHeight = $(window).scrollTop() + $(window).height(); //获取滚动条滚动距离+窗口高度
var sideHeight = $('#J_BdSide').height(); //获取J_BdSide高度
if (windowHeight > sideHeight) { //当windowHeight大于 sideHeight时 固定侧边栏
$('#J_BdSide').css({
'position' : 'fixed',//固定
right : '0px',//靠右侧
top : -(sideHeight - $(window).height())//高度是负值(J_BdSide高度和窗口高度差)
});
} else {//否则
$('#J_BdSide').css({
'position' : 'static'//默认值 不定位
});
}
});
</script>
点击打开链接

猜你喜欢

转载自blog.csdn.net/qq_38912819/article/details/80545752