I have an issue where I have a div that is positioned absoutely and I want to animate it off the page upwards (I’m animating a person jumping off the screen).
However, I need the element to be bottom: 0, but when I want the animation to finish I want the image to have top: -600px.
When I write
$("#jumper").animate({
top: "-600px"
}, 2000, 'easeInBack' );
it sets top top to 0 and then starts the animation.
Perhaps there is a way to get the ypos of the element and set top with jQuery.css() on window load?
What should I do here?
How about just animating the
bottomproperty? You could get the height of the document, then add600to it.http://jsfiddle.net/kavY4/
Otherwise, you run into browser specific issues where the
topis calculated to beauto, and the animation tries to start from that position (which ends up being 0, I guess).To make that work you would have to get the top position of
#jumperand set thetopproperty to that value manually before you animate.EDIT: The second example required
bottomto be set toautoas well.http://jsfiddle.net/kavY4/1/