JSFiddle - React, Tailwind, and code Playground

by Glynne Turner

HTML

<div id="large-gallery">
  <div class="container gallery-inner"> 
      <img src="" id="gallery-img" /> 
      <div id="active"></div>
  </div>
  <span id="prev"><i class="fa fa-chevron-circle-left"></i>
</span>
  <span id="next"><i class="fa fa-chevron-circle-right"></i>
</span>
  <span id="close"><i class="fa fa-times-circle"></i></span> 
</div>
<div class="container">
  <div class="row">
    <div class="col-sm-4 col-md-3 img-holder">
      <div class="img">
        <img class="gallery-image" src="https://thanet-web-design.com/CTE2/wp-content/uploads/2021/11/Tree.jpg" alt=""  data-imgsrc="https://thanet-web-design.com/CTE2/wp-content/uploads/2021/11/Tree.jpg" />
      </div>
    </div> 
    <div class="col-sm-4 col-md-3 img-holder">
      <div class="img">
        <img class="gallery-image" src="https://thanet-web-design.com/CTE2/wp-content/uploads//2021/12/CanaryTrailEvents1.jpg" data-imgsrc="https://thanet-web-design.com/CTE2/wp-content/uploads//2021/12/CanaryTrailEvents1.jpg" alt=""/>
      </div>
    </div> 
    <div class="col-sm-4 col-md-3 img-holder">
      <div class="img">
        <img class="gallery-image" src="https://thanet-web-design.com/CTE2/wp-content/uploads/2021/11/NightRunner.jpg" data-imgsrc="https://thanet-web-design.com/CTE2/wp-content/uploads/2021/11/NightRunner.jpg" alt=""/>
      </div>
    </div> 
    <div class="col-sm-4 col-md-3 img-holder">
      <div class="img">
        <img  class="gallery-image" src="https://s3.envato.com/files/248344327/WY0A1256.jpg" data-imgsrc="https://s3.envato.com/files/248344327/WY0A1256.jpg" alt=""/>
      </div>
    </div> 
    <div class="col-sm-4 col-md-3 img-holder">
      <div class="img">
      </div>
    </div> 
    <div class=" col-sm-4 col-md-3 img-holder">
      <div class="img">
      </div>
    </div> 
    <div class="col-sm-4 col-md-3 img-holder">
      <div class="img">
      </div>
    </div> 
  </div>
  
</div>

CSS

*{box-sizing:border-box}
.img-holder{height:200px;padding:5px;}
.img{ border: 1px solid blue; width:100%; height:100%; overflow-x:hidden;overflow-y:hidden}
.img img{min-height:100%;position:relative; width:100%; height:auto  }
#large-gallery{display:none; width:100vw; height:100vh;  z-index:999999; position:fixed }
.showgallery{display:flex !important;  background-color:rgba(0,0,0,.7); height:100vh;flex-direction: column;justify-content: center; }
.gallery-inner{width:100%; text-align:center}
#gallery-img{max-height:70vh; max-width:80vw}

#prev, #next {font-size:60px; position:absolute; top:calc (50vh - 30px);  color:#ffffff; transition: all .3s}
#close{font-size:60px; position:absolute; top:10px; right:10px;  color:#ffffff; transition: all .3s}
#prev:hover, #next:hover,#close:hover{cursor:pointer; opacity:.7}
#prev {left:calc(7vw - 30px)}
#next{right:calc(7vw - 30px)}



.img-holder{}

JavaScript

$('.gallery-image').click(function(){
  var current = $(this).index('.gallery-image');
 	var $img_src= $(this).data('imgsrc');
  $('#active').attr('data-active', current)
  $('#gallery-img').attr('src', $img_src);
  $('#large-gallery').addClass('showgallery'); 
})

$('#prev , #next').click(function(){
	 var img_count = document.getElementsByClassName('gallery-image').length;
	 var current = $('#active').data('active');
   var imgN ='';
   if($(this).attr("id") == 'prev'){ 
		if(current == 0){ 
    	imgN = img_count -1;
     }else{ 
      imgN = current -1; 
     }
   }else{
      if (current == (img_count - 1) ){
      	imgN = 0;
      }else{
      	imgN = current +1;
      }
      
   } 
	 $('#active').data('active', imgN )
   var newImg = $('.gallery-image').eq(imgN).attr('data-imgsrc');
   $('#gallery-img').attr('src',newImg);

})

$('#close').click(function(){
$('#large-gallery').removeClass('showgallery'); 
})