Is there a way to rotate a div using the scroll event? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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
10 Answers
7th Feb 2021, 2:46 PM
Abhay
Abhay - avatar
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