Javascript 获取一个页面站点的div偏移量
这里我使用了引导固定导航 我有一个像Javascript 获取一个页面站点的div偏移量,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,这里我使用了引导固定导航 我有一个像 <section id="count" class="count-section"> // here some code </section> 重新加载页面后,我得到值1539.5333404541016在滚动页面后,我总是得到值1539.5333251953125 如何从顶部固定导航测量此位置 类似的方法可能会奏效: $(window).scroll(function() { var pos = $('#count'
<section id="count" class="count-section">
// here some code
</section>
重新加载页面后,我得到值1539.5333404541016
在滚动页面后,我总是得到值1539.5333251953125
如何从顶部固定导航测量此位置 类似的方法可能会奏效:
$(window).scroll(function() {
var pos = $('#count').offset().top - $(document).scrollTop();
console.log(pos);
});
查看
$(窗口).height()
和$(文档).scrollTop()
类似的内容可能会起作用:
$(window).scroll(function() {
var pos = $('#count').offset().top - $(document).scrollTop();
console.log(pos);
});
看看
$(窗口).height()
和$(文档).scrollTop()
我想你应该在固定导航位置应用条件
$(window).scroll(function() {
var pos = $('.navbar').offset().top; //bootstrap top fixed nav
console.log(pos);
}
然后滚动并查看div焦点时的值是多少?然后您可以应用该条件。我认为您可以在固定导航位置应用该条件
$(window).scroll(function() {
var pos = $('.navbar').offset().top; //bootstrap top fixed nav
console.log(pos);
}
然后滚动并查看div焦点时的值是多少?然后您可以应用该条件。它也可以工作,但我认为top ans是合适的。谢谢你的ans。它也能工作,但我认为顶级ans是合适的。谢谢你的回复。