-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (63 loc) · 2.93 KB
/
script.js
File metadata and controls
71 lines (63 loc) · 2.93 KB
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
68
69
70
document.addEventListener('DOMContentLoaded', () => {
const filterButtons = document.querySelectorAll('.filter-btn');
const portfolioItems = document.querySelectorAll('.portfolio-item');
const modal = document.getElementById('modal');
const modalTitle = document.getElementById('modal-title');
const modalImage = document.getElementById('modal-image');
const modalDescription = document.getElementById('modal-description');
const modalMedium = document.getElementById('modal-medium');
const modalYear = document.getElementById('modal-year');
const modalPurpose = document.getElementById('modal-purpose');
const closeModalBtn = document.querySelector('.close-btn');
// Filter portfolio items by category
filterButtons.forEach(button => {
button.addEventListener('click', () => {
const category = button.getAttribute('data-category');
portfolioItems.forEach(item => {
const itemCategory = item.getAttribute('data-category');
if (category === 'all' || itemCategory === category) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
});
});
// Automatically add arrow icon next to each portfolio item name
portfolioItems.forEach(item => {
const titleElement = item.querySelector('p');
const arrowIcon = document.createElement('img');
arrowIcon.src = 'moreInfo.png';
arrowIcon.alt = 'Arrow icon';
arrowIcon.classList.add('arrow-icon');
titleElement.appendChild(arrowIcon); // Add the arrow icon to the name
});
// Open modal when a portfolio item is clicked
portfolioItems.forEach(item => {
item.addEventListener('click', () => {
const title = item.getAttribute('data-title');
const imgSrc = item.querySelector('img').getAttribute('src');
const description = item.getAttribute('data-description');
const medium = item.getAttribute('data-medium');
const year = item.getAttribute('data-year');
const purpose = item.getAttribute('data-purpose');
modalTitle.textContent = title;
modalImage.setAttribute('src', imgSrc);
modalDescription.textContent = description;
modalMedium.textContent = medium || "Not available";
modalYear.textContent = year || "Not available";
modalPurpose.textContent = purpose || "Not available";
modal.style.display = 'block';
});
});
// Close modal when the 'x' button is clicked
closeModalBtn.addEventListener('click', () => {
modal.style.display = 'none';
});
// Close modal when clicking outside the modal content
window.addEventListener('click', event => {
if (event.target == modal) {
modal.style.display = 'none';
}
});
});