How to use setInterval and clearInterval?

前端 未结 5 907
盖世英雄少女心
盖世英雄少女心 2020-11-22 03:58
function doKeyDown(event) {
    switch (event.keyCode) {
    case 32:
        /* Space bar was pressed */
        if (x == 4) {
            setInterval(drawAll, 20);         


        
5条回答
  •  孤街浪徒
    2020-11-22 04:33

    clearInterval is one option:

    var interval = setInterval(doStuff, 2000); // 2000 ms = start after 2sec 
    function doStuff() {
      alert('this is a 2 second warning');
      clearInterval(interval);
    }
    

提交回复
热议问题