title: Animate an element in real time
body: <p>I need to know the position of an img in real time in order to change its position while is going up or down. The target is animate it to the bottom 40px at the beginning and animate it to the top later. </p>
  
  <p>My code up to now is the following:</p>
  
  <pre><code>var pos = $('header img').offset().top;
  
  if( pos == 0) {
     $('header img').animate({"top": "+=40px"}, 6000);
  }else{
      $('header img').animate({"top": "-=40px"}, 6000);
  }
  </code></pre>
  
  <p>Any idea?</p>