根据屏幕高度、滚动高度、侧边栏自身高度判断,具体实现看代码,知道思路就好了
实现代码
var jWindow = $(window); jWindow.scroll(function(){ var scrollheight = jWindow.scrollTop(); var screenHeight = jWindow.height(); var sideheight = $('#j_BdSide').height(); if(scrollHeight + screenHeight > sideheight){ $('#j_BdSide').css({ 'position' : 'fixed', 'top' : '-(sideheight - screenHeight)', 'right' : 0 }); }else{ $('#J_BdSide').css({ 'position' : 'static' }); } }); //当页面加载的时候触发一次滚动 window.onload = function(){ jWindow.trigger('scroll'); }; //当窗口尺寸发生变化的时候触发滚动 jWindow.resize = function(){ jWindow.trigger('scroll'); };