Created
June 9, 2022 15:29
-
-
Save kobitoDevelopment/c13c703daedb3bcfd2ac013fc859b9da 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
| // アニメーション管理用変数 | |
| let animationFlag; | |
| function tick() { | |
| // アニメーション内容を記述 | |
| console.log("animation"); | |
| animationFlag = requestAnimationFrame(tick); // コールバック内にrequestAnimationFrameを格納することでループさせる | |
| } | |
| // アニメーション実行 | |
| tick(); | |
| // アニメーションを中断したい場合の記述 | |
| document.addEventListener("click", function () { | |
| // アニメーション中断 | |
| cancelAnimationFrame(animationFlag); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment