jQuery animate backgroundColor

前端 未结 17 2088
醉梦人生
醉梦人生 2020-11-21 07:11

I am trying to animate a change in backgroundColor using jQuery on mouseover.

I have checked some example and I seem to have it right, it works with other properties

17条回答
  •  北海茫月
    2020-11-21 07:56

    Try this one:

    (function($) {  
    
                var i = 0;  
    
                var someBackground = $(".someBackground");  
                var someColors = [ "yellow", "red", "blue", "pink" ];  
    
    
                someBackground.css('backgroundColor', someColors[0]);  
    
                window.setInterval(function() {  
                    i = i == someColors.length ? 0 : i;  
                    someBackground.animate({backgroundColor: someColors[i]}, 3000);  
                    i++;  
                }, 30);  
    
    })(jQuery);  
    

    you can preview example here: http://jquerydemo.com/demo/jquery-animate-background-color.aspx

提交回复
热议问题