0

I've got different elements each with a different transform property,

.one{transform: rotateY(10deg)}
.two{transform: rotateY(20deg)}
 //etc.

and I'm tryng to add a translateZ (through javascript) to these transform properties.

As expected adding such a value automatically overrides the pre-existing property .

Is there an easy way to get this done?

(as a workaround I thought about using transform-origin but I'd rather avoid that if it's possible)

3
  • 1
    could you post a minimal code example that shows the issue? Commented Jan 12, 2015 at 9:49
  • There's always a way, but setting a new transform inline overrides the previous transform, you need to set one transform that contains both the rotate and the translate, but getting the rotate values in javascript isn't easy either, as transform returns a matrix. Commented Jan 12, 2015 at 9:51
  • I'll try changing code to integrate transform-origin Commented Jan 12, 2015 at 10:17

1 Answer 1

1

As long as you're trying to do it only once you could just concat those string like

newTransform = element.style.getPropertyValue("transform") + "translateZ(..px)"

If you're trying to do it multiple times you'd need to check and probably replace within your style-string if there's already a translateZ value.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm looking into storing the value - manipulate it - and style.transform it back to element

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.