简体   繁体   English

jQuery .fadeOut淡出一种颜色然后消失

[英]jQuery .fadeOut fades out to a colour then disappears

I have my page content etc already implemented. 我的页面内容等已经实现。

I put a div at the top and set its height and width to 100% to fill the screen and the background to blue for now. 我将div放在顶部,并将其高度和宽度设置为100%以填充屏幕,现在将背景设置为蓝色。

I want it to fade out but as it is fading out i want the content to fade in to view. 我希望它淡出,但是随着它淡出,我希望内容淡入查看。

I have tried $('#splash').fadeOut('slow'); 我已经尝试过$('#splash')。fadeOut('slow'); the problem i have with this is that it fades out to a black grey screen then the content flashes up instead of fading into view at the same time. 我的问题是,它逐渐淡出为黑色灰色屏幕,然后内容闪烁而不是同时消失。

I have tried $("#splash").animate({opacity: "0"}); 我已经尝试过$(“#splash”)。animate({opacity:“ 0”}); but this just fades to grey and you cant see the content. 但这只是淡化为灰色,您看不到内容。

Any idea how to make the content fade into view and the splash to fade away? 有什么想法可以使内容淡入视图,并使飞溅淡出吗?

I recommend doing it with CSS, as in this example. 我建议使用CSS,如本例所示。 You can do it with just CSS like this. 您可以仅使用CSS来完成此操作。 If jQuery or js is your thing, this link also has an example on how to do that, but overall your performance is going to be much better using CSS. 如果您是jQuery或js,则此链接还提供了有关如何执行此操作的示例,但总体而言,使用CSS可以提高性能。

http://css3.bradshawenterprises.com/cfimg/ http://css3.bradshawenterprises.com/cfimg/

 #cf2 { position:relative; height:281px; width:450px; margin:0 auto; } #cf2 img { position:absolute; left:0; -webkit-transition: opacity 1s ease-in-out; -moz-transition: opacity 1s ease-in-out; -o-transition: opacity 1s ease-in-out; transition: opacity 1s ease-in-out; } #cf2 img.top:hover { opacity:0; } @keyframes cf2FadeInOut { 0% { opacity:1; } 45% { opacity:1; } 55% { opacity:0; } 100% { opacity:0; } } #cf3 img.top { animation-name: cf3FadeInOut; animation-timing-function: ease-in-out; animation-iteration-count: infinite; animation-duration: 10s; animation-direction: alternate; } 
 <div id="cf2" class="shadow"> <img class="bottom" src="http://lorempixel.com/400/200" /> <img class="top" src="http://lorempixel.com/400/200/sports" /> </div> <p id="cf_onclick">Hover over image</p> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM