简体   繁体   English

淡入淡出

[英]Fade in and fade out

How to make the div with all of the images fade in and fade out at once? 如何使div具有所有图像的淡入和淡出? The div with the images should at first be hidden, then fade in after clicking some button then fade out. 首先应隐藏具有图像的div,然后在单击某些按钮后淡入并逐渐淡出。

https://jsfiddle.net/f8juy5pb/3/ https://jsfiddle.net/f8juy5pb/3/

<div id="a">
<img id="image1" src="http://placehold.it/350x150"/>
<img id="image2" src="http://placehold.it/350x150"/>
<img id="image3" src="http://placehold.it/350x150"/>
<img id="image4" src="http://placehold.it/350x150"/>
<img id="image5" src="http://placehold.it/350x150"/>
<img id="image6" src="http://placehold.it/350x150"/>
<img id="image7" src="http://placehold.it/350x150"/>
<img id="image8" src="http://placehold.it/350x150"/>
<img id="image9" src="http://placehold.it/350x150"/>
<img id="image10"src="http://placehold.it/350x150"/>
</div>


#a img { 
    float: left;
    width: 15%;
    margin-right: 5%;
    margin-bottom: 6%;
    height: 75px;
    max-width: 100%;
    max-height: 100%;

}


#a:after {
    clear: both;
    content: "";
    display: table;
}

Use fadeIn / fadeOut with :visible to detect if the images are current display or not 使用带有:visible的 fadeIn / fadeOut来检测图像是否为当前显示

 $('button').click(function() { if ($('img:visible').length) { $('img').fadeOut(); } else { $('img').fadeIn(); } }); 
 #a img { float: left; width: 15%; margin-right: 5%; margin-bottom: 6%; height: 75px; max-width: 100%; max-height: 100%; } #a:after { clear: both; content: ""; display: table; } 
 <div id="a"> <img id="image1" src="http://placehold.it/350x150" /> <img id="image2" src="http://placehold.it/350x150" /> <img id="image3" src="http://placehold.it/350x150" /> <img id="image4" src="http://placehold.it/350x150" /> <img id="image5" src="http://placehold.it/350x150" /> <img id="image6" src="http://placehold.it/350x150" /> <img id="image7" src="http://placehold.it/350x150" /> <img id="image8" src="http://placehold.it/350x150" /> <img id="image9" src="http://placehold.it/350x150" /> <img id="image10" src="http://placehold.it/350x150" /> </div> <button>fade</button> 

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

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