Last active
July 13, 2022 07:06
-
-
Save kobitoDevelopment/c2bc6c29a4706a16970483556c26a3f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="hoge"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const hoge = document.querySelector(".hoge"); | |
| let speed = 0; | |
| let rotation = 0; | |
| window.addEventListener("wheel", function (event) { | |
| speed += event.deltaY * 0.02; | |
| }); | |
| function rot() { | |
| speed *= 0.93; // requestAnimationFrameの呼び出しで+される数値を小さくし続ける | |
| rotation += speed; | |
| hoge.style.transform = `translateX(${rotation}px)`; | |
| requestAnimationFrame(rot); | |
| } | |
| rot(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .hoge { | |
| width: 200px; | |
| height: 200px; | |
| background-color: green; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment