如何让div固定在检测到用户滚动的时候。
例如: Facebook的右边栏,当达到一定的滚动位置时,它就会卡住。
发布于 2012-03-02 18:35:07
position:fixed就是答案。
但是,如果你想知道网站是如何做的,你可以随时查看网站的源码。非常有教育意义!
发布于 2012-03-02 18:36:06
监视我们是否在滚动。
if($(window).scrollTop() > 0){
//we're scrolling our position is greater than 0 from the top of the page.
$("#element").css({'position' : 'fixed'});
}*编辑
在没有jQuery的情况下完成..
if(window.scrollTop() > 0){
document.getElementById('element').style.position="fixed";
}发布于 2013-09-13 07:44:09
我偶然看到了这篇文章,它解释了一个解决方案https://www.virendrachandak.com/techtalk/make-a-div-stick-to-top-when-scrolled-to/
https://stackoverflow.com/questions/9531754
复制相似问题