forked from Avdhesh-Varshney/blog-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
24 lines (22 loc) · 1.1 KB
/
script.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
fetch('data.json')
.then(response => response.json())
.then(data => {
const dataButtons = document.querySelectorAll('.data-btn');
dataButtons.forEach(button => {
button.addEventListener('click', () => {
const image = button.previousElementSibling;
const imageUrl = image.src;
const imageData = data.find(item => item.imageUrl === imageUrl);
if (imageData) {
document.getElementById('overlay-title').textContent = imageData.title;
document.getElementById('overlay-description').textContent = imageData.artist;
document.getElementById('overlay-link').href = imageData.link;
document.getElementById('overlay').style.display = 'flex';
}
});
});
document.getElementById('close-overlay').addEventListener('click', function() {
document.getElementById('overlay').style.display = 'none';
});
})
.catch(error => console.error('Error loading JSON:', error));