I am animating a div that is absolutely positioned. The "top" value is deturmined dynamically, so I need to use jquery to animate -20px of whatever the dyanmic "top" value is.
$("#element").animate({"top" : +-20});
Obviously the above is incorrect, but I need to simply subtract 20 from whatever "top" value the #element already has. Can I do this using the above syntax?
For instance, if #element has a top: -300px, I would need the end result to be -320px.
You have to pass it a string, prepending -=
to your number:
$("#element").animate({ top: "-=20" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With