title: compare vertical distance from the top of an element and scroll distance from top of the page
body: <p>I have problem with my js codes,I want to compare vertical distance from top of an element with scroll distance and if scroll distance is more than distance from the top of an element fixed the position of div with "thead" id in top of the page.</p>
  
  <p>my js code :</p>
  
  <pre><code>var distance = $("#thead").offset().top;
  var wdistance = $(window).scrollTop();
  if (wdistance &gt; distance) {
   alert('this is test');
  };
  </code></pre>
  
  <p>demo in</p>
  
  <p><a href="http://jsfiddle.net/mkafiyan/HmFW7/2/" rel="nofollow">jsfiddle</a></p>