Javascript/React: Randomly rotate dom element by className independently of each other

J

jobiin

Guest
A simple question that should result in a simple answer... and yet I cannot wrap my head around it.

I have a set of elements with a className and I would like to have each one rotate a random degree. Let's say between -10 and 10 degrees. Each one should have a random degree, and none should have the same.

So, visually it could look like...

element1: -2˚ rotation
element2: 3˚ rotation
element3: 7˚ rotation
element4: -9˚rotation
element5: -2˚ rotation (**error)**


Thought process would be to getElementsByClassName, then a forloop, with a random math between x and y?

This is all happening within a React app, and ideally would like to happen within a componentDid or Will mount, but within a render is fine.

Continue reading...
 
Top