-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagePopUp.js
49 lines (42 loc) · 1.26 KB
/
imagePopUp.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
/*Copyright 2023 Nick Falbo (https://nick.falbo.dev)
SPDX-License-Identifier: Apache-2.0*/
const imageArr = document.querySelectorAll('.pop-up-img');
const popUpFrame = document.querySelector('.pop-up-frame');
const exitButton = document.querySelector('.pop-up-exit-button');
const zoomedImg = document.querySelector('.zoomed-img');
const setImage = (target) => {
zoomedImg.src = `${target.src}`;
zoomedImg.alt = `Enlarged - ${target.alt}`;
}
const enlargeImage = () => {
popUpFrame.style.display = 'flex';
}
const minimizeImage = () => {
popUpFrame.style.display = 'none';
}
imageArr.forEach(target => {
target.addEventListener('click', (event) => {
event.preventDefault();
setImage(target);
enlargeImage();
})
})
// add keydown event listener for accessibility
imageArr.forEach(target => {
target.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
setImage(target);
enlargeImage();
}
})
})
exitButton.addEventListener('click', (event) => {
event.preventDefault();
minimizeImage();
})
// add keydown event listener for accessibility
exitButton.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
minimizeImage();
}
})