+ 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)
12 Réponses
+ 10
🍇 Alex Tușinean 💜 check the following code,
https://code.sololearn.com/WLN5K970lrEM/?ref=app
+ 6
🇧🇩🇳🇴🇷'🇼🇪🇸🇹🇪🇷 that is what i was trying to do.
//sorry, i meant y, not x Abhay
+ 5
https://code.sololearn.com/WJ5yPgBS6Uyd/?ref=app
This'll work on touch devices
+ 3
Abhay editted your code a bit
https://code.sololearn.com/WC0lTYJ5EuQa/?ref=app
+ 3
x position or y position?
+ 2
Abhay yes, but the scroll position shall stay the same while only the rotation changes.
+ 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 !
+ 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 !
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.