[英]Get a div offset for one page site
在這里,我使用了引導固定導航。
我有一個像
<section id="count" class="count-section">
// here some code
</section>
如果用戶滾動並在此部分看到,我將嘗試應用動畫。 所以在這里,我試圖通過測量偏移來實現。 我試過下面的代碼
$(window).scroll(function() {
var pos = $('#count').offset().top;
console.log(pos);
}
重新加載頁面后,我得到了價值1539.5333404541016
后滾動頁面我總是得到價值1539.5333251953125
。
如何從頂部固定導航中測量此位置?
這樣的事情可能會起作用:
$(window).scroll(function() {
var pos = $('#count').offset().top - $(document).scrollTop();
console.log(pos);
});
看一下$(window).height()
和$(document).scrollTop()
。
我想您要在固定的導航位置上應用條件,
$(window).scroll(function() {
var pos = $('.navbar').offset().top; //bootstrap top fixed nav
console.log(pos);
}
然后滾動查看div焦點,值是多少? 然后,您可以應用條件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.