m3.b
m3.b

Reputation: 667

Using the CSS transform property with JS - How to use cosine or other angle calculation?

when I call this in my JS :

block.style.transform = "rotate(67.5deg) skewX(45deg) scaleY(cos(45deg))";

Nothing happens on my page, and the console returns an error :

Error in parsing value for ‘transform’. Declaration dropped.

Thos problem is with the last parameter and the cosine.

I tried using Interpolation syntax for the calculation but it doesn't work.

Upvotes: 0

Views: 132

Answers (1)

ngearing
ngearing

Reputation: 1365

You will need to calculate the cos value before you assign the style.

You could use template literals to ` execute the code inline.

elem.style.transform = `rotate(67.5deg) skewX(45deg) scaleY(${Math.cos(45)})`

Upvotes: 1

Related Questions