-
-
Save ujjwal123123/e5334c1e2a1ba6349c917d4c862256f9 to your computer and use it in GitHub Desktop.
gallery-start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Image gallery</title> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> | |
<h1>Image gallery example</h1> | |
<div class="full-img"> | |
<img class="displayed-img" src="images/pic1.jpg"> | |
<div class="overlay"></div> | |
<button class="dark">Darken</button> | |
</div> | |
<div class="thumb-bar"> | |
</div> | |
<script src="main.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const displayedImage = document.querySelector('.displayed-img'); | |
const thumbBar = document.querySelector('.thumb-bar'); | |
const btn = document.querySelector('button'); | |
const overlay = document.querySelector('.overlay'); | |
images = ["pic1.jpg", "pic2.jpg", "pic3.jpg", "pic4.jpg", "pic5.jpg"]; | |
/* Looping through images */ | |
for (i = 0; i < images.length; i++) { | |
const newImage = document.createElement('img'); | |
newImage.setAttribute('src', "images/" + images[i]); | |
newImage.onclick = function () { | |
displayedImage.src = newImage.src; | |
}; | |
thumbBar.appendChild(newImage); | |
} | |
btn.addEventListener('click', function () { | |
if (overlay.style.visibility === "hidden") { | |
btn.setAttribute('class', 'dark'); | |
overlay.style.visibility = "visible"; | |
btn.textContent = "Lighten"; | |
} | |
else { | |
btn.setAttribute('class', 'light'); | |
overlay.style.visibility = "hidden"; | |
btn.textContent = "Darken"; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 { | |
font-family: helvetica, arial, sans-serif; | |
text-align: center; | |
} | |
body { | |
width: 640px; | |
margin: 0 auto; | |
} | |
.full-img { | |
position: relative; | |
display: block; | |
width: 640px; | |
height: 480px; | |
} | |
.overlay { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 640px; | |
height: 480px; | |
background-color: rgba(0,0,0,0.5); | |
visibility: hidden; | |
} | |
button { | |
border: 0; | |
background: rgba(150,150,150,0.6); | |
text-shadow: 1px 1px 1px white; | |
border: 1px solid #999; | |
position: absolute; | |
cursor: pointer; | |
top: 2px; | |
left: 2px; | |
} | |
.thumb-bar img { | |
display: block; | |
width: 20%; | |
float: left; | |
cursor: pointer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment