eabait
eabait

Reputation: 1196

CSS3 transforms: how to undo a transform operation?

I want to apply a translate transformation to a <div>, and then be able to return that <div> to its original place.

Applying the same operation with negated values doesn't return the DIV to the original place in the screen:

I want to control the undo levels, so reseting the transforms is not an option.

Upvotes: 2

Views: 1312

Answers (2)

Paul D. Waite
Paul D. Waite

Reputation: 98816

I don’t think you can apply multiple instances of the same transform function to an element. I think the second -webkit-transform:translate(); statement replaces the first, rather than acting in addition to it.

-webkit-transform: translate(0, 0); should return the element to its original (pre-translation) position. See:

Upvotes: 4

bjornd
bjornd

Reputation: 22943

Before applying transform you could save the current value of -webkit-transform. When undoing just restore the saved value.

Upvotes: 2

Related Questions