+ 11

Is there a way to rotate a div using the scroll event?

I want something to rotate in both directions(as scroll goes up and down), but the rotation must be smooth and the rotation value must be equal with the scroll distance.(i was thinking at something that could check how many px do I scroll in one way, and somehow convert them in deg to make the rotation)(forgive me but I am not sure how to descrive this)

7th Feb 2021, 2:16 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
12 Réponses
7th Feb 2021, 2:46 PM
Abhay
Abhay - avatar
+ 6
🇧🇩🇳‌🇴‌🇷‌'🇼‌🇪‌🇸‌🇹‌🇪‌🇷‌ that is what i was trying to do. //sorry, i meant y, not x Abhay
7th Feb 2021, 5:29 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 5
7th Feb 2021, 5:21 PM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar
7th Feb 2021, 3:19 PM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar
+ 3
x position or y position?
7th Feb 2021, 5:13 PM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar
+ 2
Abhay yes, but the scroll position shall stay the same while only the rotation changes.
7th Feb 2021, 4:01 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 2
🍇 Purpura S 💜 sorry i still don't understand , can you provide more details ! Or you can change my code according to what you want !
7th Feb 2021, 5:03 PM
Abhay
Abhay - avatar
+ 1
🍇 Alex Tușinean 💜 what do you mean by scrolling the same element that has to rotate? You mean that scroll should be applied on the element that is rotating ? Also you can make a button that after click will stop the rotation on specific axis then rotate on other axis , nothing difficult about it !
7th Feb 2021, 3:37 PM
Abhay
Abhay - avatar
0
🇧🇩🇳‌🇴‌🇷‌'🇼‌🇪‌🇸‌🇹‌🇪‌🇷‌ Abhay these solutions are good. But now, how could I scroll the same element that has to rotate? The actual scrolll (up and down) should change the rotation instead of the x position. I don't know if that is possible. Like locking the scroll on x, then rotating.
7th Feb 2021, 3:31 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar