[英]Keep fixed the div only while scrolling and depends on the parent div height
我不确定是否可以使用angularjs完成此操作,因为我尚未真正研究过它,但可以使用以下方法轻松完成
var fixmeTop = $('。fixme')。offset()。top; //获取元素的初始位置
$(window).scroll(function(){//分配滚动事件监听器
var currentScroll = $(window).scrollTop(); // get current position
if (currentScroll >= fixmeTop) { // apply position: fixed if you
$('.fixme').css({ // scroll to that element or below it
position: 'fixed',
top: '0',
left: '0'
});
} else { // apply position: static
$('.fixme').css({ // if you scroll above it
position: 'static'
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.