Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取一个页面站点的div偏移量_Javascript_Jquery_Twitter Bootstrap - Fatal编程技术网

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是合适的。谢谢你的回复。