Possible to fade out div border?

后端 未结 5 2213
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 16:08

I know you can fade out a

with jQuery, but I was wondering if it\'s possible to fade out a border for a
?

So I\'ve g

5条回答
  •  难免孤独
    2020-12-10 16:33

    A real fade out animation would require us to use the alpha channel. AFAIK jQuery UI's use of rgba() is very buggy, so we can use the step property to change the opacity of the border like this:

    setTimeout(function(){
    
        var div = $('.confession');
        $({alpha:1}).animate({alpha:0}, {
            duration: 1000,
            step: function(){
                div.css('border-color','rgba(0,0,0,'+this.alpha+')');
            }
        });
    
    }, 5000);
    

    I used a black border so you can notice the effect, but you can change it to whatever color you want, for example rgba(221,221,221,'+this.alpha+')'); for #DDD

    Working example: http://jsfiddle.net/victmo/2Xazx/

    Cheers!

    BTW, no plugins needed for this approach...

提交回复
热议问题