-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage-interactions.js
More file actions
33 lines (27 loc) · 1 KB
/
image-interactions.js
File metadata and controls
33 lines (27 loc) · 1 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
// homepage variable
let images = document.querySelectorAll(".image-container>a>img");
console.log(images);
let titles = document.querySelectorAll(".image-text")
//functions to change a CSS property (opacity)
function changeOpacity(){
for (var i = 0; i < images.length; i++) {
images[i].style.opacity = "0.5";
images[i].nextElementSibling.style.color = "gray";//change the text color to gray along with the image
}
this.style.opacity = '1';
this.nextElementSibling.style.color = "white";
}
function resetOpacity() {
for (var i = 0; i < images.length; i++) {
images[i].style.opacity = "1";
images[i].nextElementSibling.style.color = "white"; //reset the text color to white
}
}
// event listeners for hover on
for (var i = 0; i < images.length; i++) {
images[i].addEventListener("mouseover", changeOpacity);
}
// event listeners for hover off
for (var i = 0; i < images.length; i++) {
images[i].addEventListener("mouseout", resetOpacity);
}