淡出除一个对象外的所有对象 [英] fade out all objects except one
问题描述
所以我有一个背景覆盖整个视图的div。
里面有一个h2标签。
是否可以淡出背景,同时取消h2标签?
网站的结构阻止我将h2标签移动到外面of the div。
例如。
$('#intro')。fadeTo('slow',0.67,function(){
/ pre>
$ h2)。css(color,black);
$(h2)css(opacity,1);
解决方案这是fadeTo不可能的,因为它依赖于不透明度来控制淡入淡出,
但是,请参阅这个的答案如何使用rgba转换。
你可以看到这个小提琴淡化背景中的div,可以褪色为零不透明度以有效地使其消失。
$(function(){
setTimeout ){
$('#background')。animate({
backgroundColor:'rgba(0,0,0,0.0)'
});
},2000) ;
});
https://jsfiddle.net/p7a4xm7u/8/
So I have a div with a background that covers the entire view. Inside of that i have an h2-tag. Is it possible to fade-out the background, whilst unfading the h2-tag?
The structure of the website prevents me from moving the h2-tag outside of the div.
eg.
$('#intro').fadeTo('slow',0.67,function(){ $("h2").css("color","black"); $("h2").css("opacity","1");
解决方案This is not possible with fadeTo, because it relies on opacity to control the fade, and you can't set opacity of a child differently than opacity of the parent.
However, see this answer for how to do it using rgba transitions.
You can see this fiddle for fading the div in the background, which you can have fade to zero opacity to effectively make it disappear.
$(function () { setTimeout(function () { $('#background').animate({ backgroundColor: 'rgba(0,0,0,0.0)' }); }, 2000); });
https://jsfiddle.net/p7a4xm7u/8/
这篇关于淡出除一个对象外的所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!