forked from cs4241-21a/a1-gettingstarted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (31 loc) · 1 KB
/
index.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
const INIT_WIDTH = 15, MAX_WIDTH = 25, WIDTH_CHANGE_RATE = 0.25;
let currentWidth = INIT_WIDTH;
let hovering = false;
window.onload = () => {
let hoverImage = document.getElementById("hoverImage");
hoverImage.style.width = currentWidth.toString() + "em";
hoverImage.hidden = false
hoverImage.addEventListener("mouseenter", (e) => {
hovering = true;
}, false);
hoverImage.addEventListener("mouseleave", (e) => {
hovering = false;
}, false);
UpdateHoverImage();
}
function UpdateHoverImage() {
setTimeout(() => {
if (hovering) {
if (currentWidth < MAX_WIDTH) {
currentWidth += WIDTH_CHANGE_RATE;
hoverImage.style.width = currentWidth.toString() + "em";
}
} else {
if (currentWidth > INIT_WIDTH) {
currentWidth -= WIDTH_CHANGE_RATE;
hoverImage.style.width = currentWidth.toString() + "em";
}
}
UpdateHoverImage();
}, 1);
}