【问题标题】:How to Fade out background-color of a div [duplicate]如何淡出div的背景颜色[重复]
【发布时间】:2015-09-02 12:29:57
【问题描述】:

我正在尝试使 div 背景颜色淡出缓慢

html

<div class="bg">...........</div>

我用过这个jquery

$('.bg').css('backgroundColor','#dedede');
setTimeout(function(){
    $('.bg').css('backgroundColor','#ffffff'); 
}, 1000);

如何添加淡出效果?

【问题讨论】:

    标签: jquery css


    【解决方案1】:

    您可以使用fadeOut: $('.bg').css('backgroundColor', '#dedede');

    $('.bg').fadeOut(1000);
    

    Demo

    您可以animate:

    $('.bg').animate({
        'opacity': '0'
    }, 1000);
    

    Demo

    更新

    $('.bg').css('backgroundColor', '#dedede');
    $('.bg').animate({
        'opacity': '0.5'
    }, 1000, function () {
        $('.bg').css({
            'backgroundColor': '#fff',
            'opacity': '1'
        });
    });
    

    Demo

    【讨论】:

    • 但问题是,这个fadeOut效果隐藏了所有的div元素,而不仅仅是背景色!!
    • 我希望文本保持静止并且不要淡出
    • @Devstar 检查更新
    猜你喜欢
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-01
    • 2014-06-21
    • 1970-01-01
    • 2020-05-13
    • 2012-05-31
    相关资源
    最近更新 更多