[英]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.