JQuery background color animate not working

前端 未结 9 1858
温柔的废话
温柔的废话 2020-12-10 05:27

I want to change the background color of \'exampleDiv\' from the original white background to when I call the code below to immediate change the background yellow and then f

9条回答
  •  时光取名叫无心
    2020-12-10 05:52

    I had the same problem and I was able to get everything to work when I included the correct js files.

    
    
    
    

    I took it a step further and found a nice extension someone wrote.

    jQuery.fn.flash = function (color, duration) {
       var current = this.css('backgroundColor');
       this.animate({ backgroundColor: 'rgb(' + color + ')' }, duration / 2)
       .animate({ backgroundColor: current }, duration / 2);
    }
    

    The above code allows me to do the following:

    $('#someId').flash('255,148,148', 1100);
    

    That code will get your element to flash to red then back to its original color.

    Here's some sample code. http://jsbin.com/iqasaz/2

提交回复
热议问题