forked from alwaysPasindu/Life_Below_Water_Website_UNSDG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGallery.js
67 lines (51 loc) · 2.29 KB
/
Gallery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Get all elements with IDs starting with "myImg"
var images = document.querySelectorAll('[id^="myImg"]');
// Iterate through each image and add click event listener
images.forEach(function(img) {
img.onclick = function() {
var modalId = 'myModal' + this.id.slice(-1);
var modal = document.getElementById(modalId);
modal.style.display = "block";
}
});
// Get all elements with class "close"
var closeButtons = document.getElementsByClassName("close");
// Iterate through each close button and add click event listener
for (var i = 0; i < closeButtons.length; i++) {
closeButtons[i].onclick = function() {
var modal = this.closest('.modal');
modal.style.display = "none";
}
}
// Close the modal when clicking outside of it
window.onclick = function(event) {
if (event.target.classList.contains('modal')) {
event.target.style.display = "none";
}
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
document.addEventListener('DOMContentLoaded', function() {
const filterButtons = document.querySelectorAll('.button-group .button');
const thumbnails = document.querySelectorAll('.Thumbnail');
filterButtons.forEach(button => {
button.addEventListener('click', function() {
const filter = this.getAttribute('data-filter');
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
this.classList.add('active');
thumbnails.forEach(thumbnail => {
if (filter === 'all' || thumbnail.getAttribute('data-filter') === filter) {
thumbnail.style.display = 'inline-block';
} else {
thumbnail.style.display = 'none';
}
});
});
});
});