Fade the background-color of a span tag with JQuery

前端 未结 12 684
北恋
北恋 2020-12-09 16:20

I\'m trying to fade the background-color of a span tag using JQuery to emphasize when a change has occured. I was thinking the code would be someting like the following ins

12条回答
  •  孤城傲影
    2020-12-09 16:35

    Another solution without jQuery UI https://stackoverflow.com/a/22590958/781695

    //Color row background in HSL space (easier to manipulate fading)
    $('span').css('backgroundColor','hsl(0,100%,50%');
    
    var d = 1000;
    for(var i=50; i<=100; i=i+0.1){ //i represents the lightness
        d  += 10;
        (function(ii,dd){
            setTimeout(function(){
                $('span').css('backgroundColor','hsl(0,100%,'+ii+'%)'); 
            }, dd);    
        })(i,d);
    }
    

    Demo : http://jsfiddle.net/5NB3s/3/

提交回复
热议问题