Jquery change background color

前端 未结 3 1197
耶瑟儿~
耶瑟儿~ 2020-11-29 19:17

I was trying out jquery with this example:

 $(document).ready(function(){
      $(\"button\").mouseover(function(){
        $(\"p#44.test\").css(\"backgroun         


        
3条回答
  •  醉酒成梦
    2020-11-29 20:08

    The .css() function doesn't queue behind running animations, it's instantaneous.

    To match the behaviour that you're after, you'd need to do the following:

    $(document).ready(function() {
      $("button").mouseover(function() {
        var p = $("p#44.test").css("background-color", "yellow");
        p.hide(1500).show(1500);
        p.queue(function() {
          p.css("background-color", "red");
        });
      });
    });
    

    The .queue() function waits for running animations to run out and then fires whatever's in the supplied function.

提交回复
热议问题