Can anyone help me figure out how to use the jquery .css() function without overwriting existing values, but instead adding additional values to css properties?
For example, I have an element that currently has the css transform:translate(-50%, -50%)
. I want to use the jQuery .css() function to ADD transform: rotate(90deg)
, but every time I try it, it just overwrites the original value.
If my explanation is unclear, please take a look at this fiddle for clarification. http://jsfiddle.net/justinbchristensen/mvhwbjLo/1/
In the Fiddle, you'll notice that clicking the button causes the square to lose its initial transformation, slide down, and rotate. However, subsequent clicks only rotate the square because the 'transform:translate' property is not being lost.
I would prefer not to specify the entire transformation in my .css() function like
element.css('transform', 'translate(-50%,-50%) rotate(90deg)'
; I just want to add the rotation to the existing transformation.
Is there a way to achieve this desired outcome?