stop settimeout in recursive function

后端 未结 7 2132
旧时难觅i
旧时难觅i 2020-12-01 11:24

my problem is that I can not stop a timer.

I had this method to set a timeout from this forum. It supposed to store the identifyer in the global variable. By accid

7条回答
  •  醉话见心
    2020-12-01 11:49

    (function(){

    $('#my_div').css('background-color', 'red');
    $('#my_div').hover(function(){
    var id=setTimeout(function() {
        $('#my_div').css('background-color', 'green');
    }, 2000);
    
    var id=setTimeout(function() {
        $('#my_div').css('background-color', 'blue');
    }, 4000);
    var id=setTimeout(function() {
        $('#my_div').css('background-color', 'pink');
    }, 6000);
    
        })
    
    $("#my_div").click(function(){  
            clearTimeout(id);
    
            })
    

    })();

提交回复
热议问题