0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JavaScript タイマー機能 メモ

Last updated at Posted at 2023-08-16

タイマー機能

  • JavaScriptのタイマー機能はsetInterval()crearInterval()メソッドがある

setIntervalメソッド

  • setInterval()メソッドは一定時間ごとに処理を実行する

crearIntervalメソッド

  • crearInterval()はタイマー機能を止めたい時に用いる
  • clearInterval()メソッドの引数にsetInterval()メソッドの戻り値(止めたい処理の変数)を渡すことで、タイマーを止めることができる。

コード

time.js
const id = setInterval(() => {
    処理;
    if(処理を中断したい条件){
        crearInterval(id);
    }
}, 一定時間);
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?