+ 2

Web -How to rotate an image / div x deg every time this button is clicked?

X = 90 deg; img = the image; btn 🔄 = button; -- Ok now every time the 'btn' is clicked, the image rotates 90 deg. Example: this is straight (normal):⬆️. On the first click: ⬅️; Second click: ⬇️; Third click: ➡️; Ok .. u get the idea -right-- Anyways I need it to be like that if someone would make me a little code to rotate ___. use a div element, imoji, or image for the code. Thanks!

29th Jun 2019, 4:53 AM
Ginfio
Ginfio - avatar
2 Respostas
+ 4
you can use transform: rotate(90deg) positive angle will rotate the lement in clockwise, negative will rotate in counterclockwise havent tested it, could be wrong var rot=0; function rotateit(){ rot=(rot<=-360?0:rot-90); theelement.style.transform = `rotate(${rot}deg`; }
29th Jun 2019, 5:24 AM
Taste
Taste - avatar
29th Jun 2019, 7:46 AM
Calviղ
Calviղ - avatar