Coder Wrap provides free to use snippets Coder Wrap provides free to use snippets

Back to Gallery
Preview Source Code
Download
HTML
CSS
			/**Typeo CSS Start**/
@import url('https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,400;0,500;0,700;0,800;1,300;1,400;1,500;1,600;1,700&display=swap');

* {
	box-sizing: border-box;
}

body {
	margin: 0px;
	background-color: #fff;
}

img {
	max-width: 100%;
}

/**Typeo CSS End**/
.gallery2-scn, .gallery2-scn * {
	--page-width: 1330px;
	--base-fm: 'Rubik', sans-serif;
	--title-size: 40px;
	--base-size: 18px;
	--white-clr: #ffffff;
	--theme-clr: #1ea69a;
	--bg-clr: #F9F6F2;
}

.page-width {
	max-width: var(--page-width);
	padding: 0 15px;
	margin: auto;
	width: 100%;
}

.gallery2-scn {
	background:-moz-linear-gradient(53deg, rgba(0, 255, 235, 1) 0%, rgba(76, 175, 80, 1) 100%); 
background:-webkit-linear-gradient(53deg, rgba(0, 255, 235, 1) 0%, rgba(76, 175, 80, 1) 100%);
background:-o-linear-gradient(53deg, rgba(0, 255, 235, 1) 0%, rgba(76, 175, 80, 1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4CAF50', endColorstr='#00FFEB', GradientType=0 );
background:-ms-linear-gradient(53deg, rgba(0, 255, 235, 1) 0%, rgba(76, 175, 80, 1) 100%);
background:linear-gradient(53deg, rgba(0, 255, 235, 1) 0%, rgba(76, 175, 80, 1) 100%);
	width: 100%;
	padding: 60px 0px;
	font-family: var(--base-fm);
	font-size: var(--base-size);
	color: var(--white-clr);
	display: flex;
	flex-flow: row wrap;
	align-items: center;
	text-align: center;
}
.gallery2-scn p {
    max-width: 860px;
    margin: 15px auto;
}
.gallery2-scn h2 {
	font-size: var(--title-size);
	color: var(--white-clr);
	margin: 0px 0 20px 0;
	text-align: center;
	display: inline-block;
	width: 100%;
}

.gallery-list {
	display: flex;
	flex-flow: row wrap;
	width: calc(100% + 30px);
	margin-left: -15px;
	margin-top: 20px;
}

.gallery-list .gallery-item {
	width: 33.33%;
	cursor: pointer;
	overflow: hidden;
	position: relative;
}
.gallery-list .gallery-item:before{
	content:'';
	position: absolute;
	left: 0px;
	top: 0px;
	bottom: 0px;
	right: 0px;
	margin: auto;
	background-image: url(https://coderwrap.com/wp-content/uploads/2023/04/search-icon.png);
	background-repeat: no-repeat;
	width: 50px;
	height: 50px;
	background-size: 100% 100%;
	z-index: 1;
	opacity: 0;
	pointer-events: none;

}
.gallery-list .gallery-item img {
	display: block;
	transition: 0.5s all;
	width: 100%;
	pointer-events: none;
	transform: scale(1.02);
}

.gallery-list .gallery-item:hover img {
	transform: scale(1.1);
}
.gallery-list .gallery-item:hover:before{
	opacity: 1;
}



/**Gallery Popup**/
.gModel-overlay {
	width: 100%;
	height: 100%;
	position: fixed;
	left: 0px;
	top: 0px;
	background-color: rgba(0, 0, 0, 0.5);
	z-index: 999;
}

.gallerymodel {
	pointer-events: none;
	opacity: 0;
	transition: 0.5s all;
}

.gallerymodelshow {
	pointer-events: auto;
	opacity: 1;
}
.gallerymodel .gallery-list .gallery-item:before{
	opacity: 0;
}
.gallerymodel .gallery-list {
	margin: 0px;
	width: 100%;
	overflow: hidden;
	max-width: 1000px;
	width: 100%;
	margin: auto;
	position: fixed;
	left: 0px;
	right: 0px;
	top: 50%;
	transform: translateY(-50%);
	z-index: 9999;
}
.gallerymodel .gallery-list .gallery-item:before {
	content: normal;
}
.gallerymodel .gallery-list .gallery-item {
	width: 100%;
	margin: 0px;
	display: none;
}

.gallerymodel .gallery-list .gallery-item.active {
	display: block;
}
.gModel-close {
	color: #fff;
	z-index: 9999;
	position: fixed;
	right: 15px;
	top: 15px;
	font-weight: 300;
	font-size: 30px;
	cursor: pointer;
}


@media(max-width:1100px) {
	.gallerymodel .gallery-list {
		width: calc(100% - 30px);
	}
	.gallery-cont {
    font-size: calc(var(--title-size) - 25px);
    bottom: 0;
    padding: 10px;
}
.gallerymodel .gallery-cont {
    font-size: calc(var(--title-size) - 15px);
    padding: 15px 5px;
}
}

@media(max-width:767px) {
	.gallery2-scn {
		padding: 20px 0px;
		font-size: calc(var(--base-size) - 4px);
	}

	.gallery2-scn h2 {
		font-size: calc(var(--title-size) - 10px);
	}

	.gallery-list {
		width: calc(100% + 10px);
		margin-left: -5px;
		margin-top: 10px;
	}

	.gallery-list .gallery-item {
		width: 50%;
	}
	
	.gModel-close {
		font-size: 24px;
	}
}
JS
//Append Model Popup Code
const div =	document.createElement("div");
const gmodelClass = div.setAttribute("class", "gallerymodel");
document.querySelector('.gallery2-scn').appendChild(div);
document.querySelector('.gallerymodel').innerHTML ="🗙";
//.appendChild(div);

document.querySelector(".gallery-list .gallery-item:first-child").classList.add('active');
const galleryList = document.querySelector(".gallery-list");
const clonedGallery = galleryList.cloneNode(true);
document.querySelector(".gallerymodel").appendChild(clonedGallery);
let galleryItems = document.querySelectorAll('.gallery-list .gallery-item');
galleryItems.forEach(function(item) {
 item.addEventListener('click', function(e) {
   galleryItems.forEach(function(item) {
     item.classList.remove('active');
   });
   e.target.classList.add('active'); 
 });
});

/**Model Click Start**/

let items = document.querySelectorAll('.gallery-list .gallery-item[data-gallery]');
items.forEach(function(item) {
  item.addEventListener('click', function(e) {
    let gallery = e.target.getAttribute('data-gallery');
    let listItems = document.querySelectorAll('.gallery-list .gallery-item[data-gallery="' + gallery + '"]');
    listItems.forEach(function(listItem) {
      listItem.classList.add('active');
    });
    document.querySelector('.gallerymodel').classList.add('gallerymodelshow');
    
  });
});
/**Model Click Start**/

//Model Close
 document.querySelector('.gModel-close').addEventListener('click', function(e) {
  document.querySelector('.gallerymodel').classList.remove('gallerymodelshow'); 
 });

Related Snippets

Leave a comment

Your email address will not be published. Required fields are marked *