Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在我的网站上想要的是滚动时跟随的 div,嗯,这并不难,因为有很多网站解释了如何做到这一点。但我找不到的是如何设置开始和结束位置。
我希望边栏在窗口顶部接触它时开始浮动,我希望它在容器底部时停止,现在它浮动在页脚上。
谢谢。
我想通了,我用 jQuery 计算了scrollTop();它,当它到达点时,例如 250 像素,我做addClass('fixed');了固定并停留在页面上。
scrollTop();
addClass('fixed');
为了让它在某个点停留在底部,我计算了底部边距,当它达到给定的底部边距时,我确实removeClass('fixed').css({position: 'absolute', bottom: '0px'});让它保持在其父级 100% 高度 div 的底部。
removeClass('fixed').css({position: 'absolute', bottom: '0px'});
我希望你明白。