0

I have a method which takes in the optional rotate value from the caller. Which I am applying in the following manner when the transform needs to happen:

element.style.transform = "rotate(" + (this.rotate || 0) + "deg)";

If there is no value passed to the method resulting in this.rotate not being defined and the value for rotate is set to 0 degrees, does the browser's rendering engine optimize this to not perform any transformation or will the browser spend cycles attempting the css transform?

If yes, I will have to add an if statement before attempting the transform.

fallenprogrammr
  • 189
  • 1
  • 4
  • I think this could depend on a few things, what data type is this.rotate and do you set an initial value? would different browser's behave differently - I think what i'm trying to say is i would probably wrap the statement in an if statement, hard to say. – Dylan Anlezark Sep 18 '19 at 02:53
  • A better approach would be to skip trying to apply the style if you get a zero, null or undefined value, or set it to the initial value. – beerwin Sep 18 '19 at 06:29
  • the browser will apply the 0 rotation and you may have unexpected result because it will create stacking context and containing block for fixed element https://stackoverflow.com/q/15194313/8620333 – Temani Afif Sep 18 '19 at 08:09

0 Answers0