mark smith mark smith - 1 month ago 7
jQuery Question

Moving from position A to position B slowly with animation

I have a simple jQuery animation using

fadein
and it works but once faded in... I wish to MOVE using TOP property 30 pixels upwards, but slowly.

This is what I have so far:

$('#Friends').fadeIn("slow");


I have both jQuery and jQuery UI loaded...

Answer

Use jquery animate and give it a long duration say 2000

$("#Friends").animate({ 
        top: "-=30px",
      }, duration );

The -= means that the animation will be relative to the current top position.

Note that the Friends element must have position set to relative in the css:

#Friends{position:relative;}