LoginSignup
22
23

More than 5 years have passed since last update.

js定期処理

Last updated at Posted at 2014-09-12

jsで定期的に実行する方法。
地味に詰まったのでメモ

javascript
var StartTimer, StopTimer, Timer, time, timerID;

time = 0;
timerID = 0;

StartTimer = function() {
  timerID = setInterval(Timer/*定期的に呼び出す関数名*/, 1000/*呼び出す間隔*/);
};

StopTimer = function() {
  clearInterval(timerID);
};

Timer = function() {
  time = time + 1;
  console.log(time);
  if (time > 180) {
    StopTimer();
    return alert("タイマー");
  }
};

StartTimer();
22
23
0

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
22
23