setInterval(function(),time) change time on runtime

后端 未结 6 1329
粉色の甜心
粉色の甜心 2020-12-11 04:08

I want to change setInterval function time when my code is running.

I try this



        
6条回答
  •  旧时难觅i
    2020-12-11 04:25

    timer = setInterval(come, 0); // zero isn't a valid interval...
    

    You probably wants:

    come();
    timer = setInterval(come, 10000);
    

    docs on MDN:

    delay is the number of milliseconds (thousandths of a second) that the setInterval() function should wait before each call to func. As with setTimeout, there is a minimum delay enforced.

    And:

    Historically browsers implement setTimeout() "clamping": successive setTimeout() calls with delay smaller than the "minimum delay" limit are forced to the use at least the minimum delay. The minimum delay, DOM_MIN_TIMEOUT_VALUE, is 4 ms (stored in a preference in Firefox: dom.min_timeout_value), with a DOM_CLAMP_TIMEOUT_NESTING_LEVEL of 5ms.

提交回复
热议问题