Satu Sultana Satu Sultana - 2 years ago 80
jQuery Question

Get a div offset for one page site

Here I have used bootstrap fixed navigation.

I have a section like

<section id="count" class="count-section">
// here some code

I am trying to apply an animation, if user scroll and see on this portion. So here I am trying to make it by measure offset. I have tried below code

$(window).scroll(function() {
var pos = $('#count').offset().top;

After reload the page I got value
after scroll page I always get value

How can I measure this position from my top fixed navigation ?

Answer Source

Something like this might work:

$(window).scroll(function() {
    var pos = $('#count').offset().top - $(document).scrollTop();

Take a look at $(window).height() and $(document).scrollTop().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download