recursive clearInterval does not work

后端 未结 1 1954
挽巷
挽巷 2021-01-28 00:02

I have the following function in javaScript. This function is called when i detect a need to re-load the stylesheet. for example, doe to user language change, so the text won\'t

相关标签:
1条回答
  • 2021-01-28 00:44

    Is it possible you are starting the timer more than once? Could you try:

    var timeout_id = (function() {
        if (timeout_id) {
            // a timer is already running!
            clearInterval(timeout_id);     // stop it - or you could just return and not create a new one
        }
        return setInterval(function() {
                if (link[sheet] && link[sheet][cssRules].length) {
                    clearInterval(timeout_id);                 
                    that.onStyleReset();
                }
            }, 10)
        })();
    
    0 讨论(0)
提交回复
热议问题