.delay() not working when changing background-color of

前端 未结 3 859
半阙折子戏
半阙折子戏 2021-01-22 06:40

I am just learning JQUERY and I have been playing around with delay() I wrote a fiddle to show you... What I am trying to do is when a button is clicked, change the background-c

3条回答
  •  广开言路
    2021-01-22 06:58

    delay only works for items in the queue (such as animations).

    For anything else, use a regular old timer:

    $("#change").click(function() {
        var $el = $(".animation");
    
        $el.css("background", "blue");
    
        setTimeout(function () {
            $el.css("background", "red");
        }, 700);
    });
    

提交回复
热议问题