Javascript 制作固定在滚动上的Div
如何使div固定在用户检测滚动时Javascript 制作固定在滚动上的Div,javascript,jquery,html,css,Javascript,Jquery,Html,Css,如何使div固定在用户检测滚动时示例:Facebook的右侧边栏,当达到某个滚动位置时,它会被卡住。位置:修复。 但是,如果你想知道网站是如何运作的,你可以随时查看网站的来源。很有教育意义 不确定这是不是你的意思 但是您可以添加CSS属性位置:fixed;即使在滚动之后,也可以将其显示在sam位置 if($(window).scrollTop() > 0){ //we're scrolling our position is greater than 0 from the top of
示例:Facebook的右侧边栏,当达到某个滚动位置时,它会被卡住。
位置:修复。
但是,如果你想知道网站是如何运作的,你可以随时查看网站的来源。很有教育意义 不确定这是不是你的意思
但是您可以添加CSS属性位置:fixed;即使在滚动之后,也可以将其显示在sam位置
if($(window).scrollTop() > 0){
//we're scrolling our position is greater than 0 from the top of the page.
$("#element").css({'position' : 'fixed'});
}
监视我们是否正在滚动
if($(window).scrollTop() > 0){
//we're scrolling our position is greater than 0 from the top of the page.
$("#element").css({'position' : 'fixed'});
}
*编辑
不用jQuery就可以做到
将jQuery与滚动锁插件结合使用:我遇到了这篇文章,其中解释了一个解决方案我之前使用过这个解决方案。scrollTop不是jQuery特有的,但它的其余部分是。