title: Using .offset().top to find Elements position on page
body: <p>I have a DIV I want to scroll with the page but it's not visible above the fold so I'm using this.</p>
  
  <pre><code>$(window).scroll(function() {
      // Get scrolling position of document   
      var scrollYpos = $(document).scrollTop();
  
      // if its more than the top of the element
      if (scrollYpos &gt; 551 ) {
  
           // Add a margin to the top 
           $('#scrollingDiv').animate({'margin-top': scrollYpos - 541 }, {duration: 300, queue: false});
      } else {
           $('#scrollingDiv').animate({'margin-top': 0 }, {duration: 200, queue: false});
      }}); // end scroll
  </code></pre>
  
  <p>ATM I'm giving it the vertical position of the DIV manually (551px). I want to do it dynamically.</p>
  
  <pre><code>var elYpos = $('#scrollingDiv').offset().top
  </code></pre>
  
  <p>So this finds the vertical position of the element on the page but when the element moves this changes which screws the rest up.</p>
  
  <p>How can i get the position of the element once? </p>