简体   繁体   English

弹性框图像选择

[英]Flex box image selection

I have a window with four images inside a responsive flex grid. 我有一个窗口,其中有四个图像位于响应式弹性网格内。 I would like when clicking an image, this one gets width=100% covering (or hiding) the others always inside the flexbox. 我想单击图像时,该图像的width=100%覆盖(或隐藏)其他图像始终在flexbox内。

I guess is with jQuery and JavaScript but I'm not able to find the way. 我猜想是jQuery和JavaScript,但我找不到方法。 Any help? 有什么帮助吗?

Thanks. 谢谢。

如该图所示

 .wrap {display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex;} .container {box-shadow: 0.075rem 0 0 0 #C9C9C9,0 0.075rem 0 0 #C9C9C9,0.075rem 0.075rem 0 0 #C9C9C9, 0.075rem 0 0 0 #C9C9C9 inset,0 0.075rem 0 0 #C9C9C9 inset; display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; float:left;} .half {margin: 0.25rem;} .photo {width: 15rem; max-width:100%; } 
 <div class="wrap"> <div class="container"> <div class="half"> <div id="quarter1"> <a href=""><img class="photo" src="http://letsprattle.com/image/prattle-icon-square-white.png" class="" alt="" title=""></a> </div> <div id="quarter2"> <a href=""><img class="photo" src="http://yvonnemichaelides.com/wp-content/uploads/2016/01/clock2.gif" class="" alt="" title="" ></a> </div> </div> <div class="half"> <div id="quarter3"> <a href=""><img class="photo" src="https://cdn.shopify.com/s/files/1/0387/1545/products/product_analysis_1024x1024.png?v=1426535435" class="" alt="" title="" ></a> </div> <div id="quarter4"> <a href=""><img class="photo" src="http://www.northperthcommunityhospice.org/images/icons/calendar-icon.png" class="" alt="" title="" ></a> </div> </div> </div> </div> 

I have made few changes to your HTML structure. 我对您的HTML结构进行了一些更改。 Run the below snippet 运行以下代码段

 var classname = document.getElementsByClassName("photoContainer"); var containerWidth = document.getElementsByClassName('container')[0].offsetWidth; var myFunction = function(ev) { if(this.classList.contains('expandImage')) { this.classList.remove('expandImage'); for (var i = 0; i < classname.length; i++) { classname[i].classList.remove('hideImage'); } return; } for (var i = 0; i < classname.length; i++) { classname[i].classList.add('hideImage'); } this.classList.remove('hideImage'); this.classList.add('expandImage'); this.style.width = containerWidth; }; for (var i = 0; i < classname.length; i++) { classname[i].addEventListener('click', myFunction, false); } 
 .wrap { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; } .container {box-shadow: 0.075rem 0 0 0 #C9C9C9,0 0.075rem 0 0 #C9C9C9,0.075rem 0.075rem 0 0 #C9C9C9, 0.075rem 0 0 0 #C9C9C9 inset,0 0.075rem 0 0 #C9C9C9 inset; display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; float:left; position: relative;} .half {margin: 0.25rem;} .photo {width: 15rem; max-width:100%; } .hideImage { display: none } .expandImage > img { width: 100%; } 
 <div class="wrap"> <div class="container"> <div class="half"> <div id="quarter1" class="photoContainer"> <img class="photo" src="http://letsprattle.com/image/prattle-icon-square-white.png" class="" alt="" title=""> </div> <div id="quarter2" class="photoContainer"> <img class="photo" src="http://yvonnemichaelides.com/wp-content/uploads/2016/01/clock2.gif" class="" alt="" title="" > </div> </div> <div class="half"> <div id="quarter3" class="photoContainer"> <img class="photo" src="https://cdn.shopify.com/s/files/1/0387/1545/products/product_analysis_1024x1024.png?v=1426535435" class="" alt="" title="" > </div> <div id="quarter4" class="photoContainer"> <img class="photo" src="http://www.northperthcommunityhospice.org/images/icons/calendar-icon.png" class="" alt="" title="" > </div> </div> 

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

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