Possible to fade out div border?

后端 未结 5 2205
爱一瞬间的悲伤
爱一瞬间的悲伤 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:25

    The solution below should meet all of your posted criteria:

    Wait 5000 ms (5 sec), then animate a fade out of the border that lasts 500 ms (.5 sec).

    $(".confession").delay(5000).animate({borderWidth: "0"}, 500);
    

    Working example: http://jsfiddle.net/ECRLW/

    Since the above solution seems to be unable to animate the borderWidth fade with some browsers, the only other way I would know how to accomplish what you want with jQuery would be to use setTimeout():

    function shrinkBorder(){
        var e = $(".confession");
        var eBorderWidth = e.css("border-width");
        if(eBorderWidth != "0px"){
            e.css("border-width",(eBorderWidth.split("px")[0]-1));
            setTimeout(shrinkBorder, 50);
        }
    }
    
    setTimeout(shrinkBorder, 5000);
    

    Working example: http://jsfiddle.net/mmfMG/

提交回复
热议问题