Animate background color like a progress bar in jQuery

前端 未结 11 2175
南笙
南笙 2021-02-05 23:11

I have a div which has some text content( eg: My Name ) and the div is in RED background colour

11条回答
  •  逝去的感伤
    2021-02-05 23:43

    Or you could do the math and do the color change. http://jsfiddle.net/rustyDroid/WRExt/2/

    > $("#btn").click(function(){
    >     $('#bar').animate({ width: '300px' }, 
    >     {
    >         duration:10000,
    >         easing:'linear',
    >         step:function(a,b){
    >             var pc = Math.ceil(b.now*255/b.end);
    >             var blue = pc.toString(16);
    >             var red = (255-pc).toString(16);
    >             var rgb=red+"00"+blue;
    >             $('#bar').css({
    >                 backgroundColor:'#'+rgb
    >             });            
    >         }
    >     })
    >      });
    

提交回复
热议问题