I know that the original css value from the style sheet can be assigned using: $('#id').css('property', ''); but is there a way to retrieve the value without changing the property in the object? Note that may be different from retrieving the current value because it may have changed from the style sheet value.
Possible "solutions" (untested)
var originalTopPos = $("#testPic").css("top");
....
$("#testPic").animate({"top": originalTopPos + "px"},"slow");
I'm using many images though... so it is a bit more complicated than that.
(I want to animate it from the current to original value, not just jump from one value to the other)
var currentTopPos = $("#testPic").css("top");
var originalTopPos = $("#testPic").css("top", "").css("top");
$("#testPic").css("top", currentTopPos + "px")
$("#testPic").animate({"top": originalTopPos + "px"},"slow");
I found the answer....
$(this).attr("customAttributeName", $(this).position().top);
then you can recall it with:
$(this).attr("customAttributeName");
The easiest way to do this depends on whether you want to push the current value or the original. Since you say original, the surest way is to (if you're using JQuery) create a script within $(document).ready(...)
that executes first and stores values for everything to variables.
The second way is to do $(this).css("style-name","")
(the null argument resets to default).
If you are simply pushing the current value, you can do the similar thing with the variables. myVar = $(this).css("style-name")
returns the current attribute value. Do not do var myVar = ...
. Its just myVar
. My browser yelled at me about that.
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