Skip to content

Instantly share code, notes, and snippets.

@kobitoDevelopment
Last active July 13, 2022 07:06
Show Gist options
  • Select an option

  • Save kobitoDevelopment/c2bc6c29a4706a16970483556c26a3f6 to your computer and use it in GitHub Desktop.

Select an option

Save kobitoDevelopment/c2bc6c29a4706a16970483556c26a3f6 to your computer and use it in GitHub Desktop.
<div class="hoge"></div>
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();
.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