Jquery 如何淡出div的背景色
我正试图使一个div背景色淡出缓慢 htmlJquery 如何淡出div的背景色,jquery,css,Jquery,Css,我正试图使一个div背景色淡出缓慢 html <div class="bg">...........</div> 如何添加淡出效果 您可以使用淡出功能: $('.bg').css('backgroundColor','dededede') 或 您可以设置动画: $('.bg').animate({ 'opacity': '0' }, 1000); 更新 $('.bg').css('backgroundColor', '#dedede'); $('.bg')
<div class="bg">...........</div>
如何添加淡出效果 您可以使用淡出功能: $('.bg').css('backgroundColor','dededede') 或 您可以设置动画:
$('.bg').animate({
'opacity': '0'
}, 1000);
更新
$('.bg').css('backgroundColor', '#dedede');
$('.bg').animate({
'opacity': '0.5'
}, 1000, function () {
$('.bg').css({
'backgroundColor': '#fff',
'opacity': '1'
});
});
但问题是,这种淡出效果隐藏了所有div元素,而不仅仅是背景色!!我希望文本保持静止,不要消失too@Devstar检查更新
$('.bg').animate({
'opacity': '0'
}, 1000);
$('.bg').css('backgroundColor', '#dedede');
$('.bg').animate({
'opacity': '0.5'
}, 1000, function () {
$('.bg').css({
'backgroundColor': '#fff',
'opacity': '1'
});
});