Skip to content

Instantly share code, notes, and snippets.

@kobitoDevelopment
Created June 9, 2022 15:29
Show Gist options
  • Select an option

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

Select an option

Save kobitoDevelopment/c13c703daedb3bcfd2ac013fc859b9da to your computer and use it in GitHub Desktop.
// アニメーション管理用変数
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