-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (33 loc) · 1.23 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
36
37
38
39
40
41
42
43
44
let pupils = document.getElementsByClassName('pupil');
let pupilsArr = Array.from(pupils);
// pupils movements
let pupilStartPoint = -100;
let pupilRange = 200;
// Mouse X position
let mouseXStartPoint = 0;
let mouseXEndPoint = window.innerWidth;
let currentXPosition = 0;
let fracXValue = 0;
// Mouse Y position
let mouseYEndPoint = window.innerHeight;
let currentYPosition = 0;
let fracYValue = 0;
let mouseXRange = mouseXEndPoint - mouseXStartPoint;
const mouseMove = (event) => {
currentXPosition = event.clientX - mouseXStartPoint;
fracXValue = currentXPosition / mouseXRange;
currentYPosition = event.clientY;
fracYValue = currentYPosition / mouseYEndPoint;
let pupilXCurrentPositon = pupilStartPoint + (fracXValue * pupilRange);
let pupilYCurrentPositon = pupilStartPoint + (fracYValue * pupilRange);
pupilsArr.forEach(curPupil => {
curPupil.style.transform = `translate(${pupilXCurrentPositon}px, ${pupilYCurrentPositon}px)`;
});
}
const windowResize = (event) => {
mouseXEndPoint = window.innerWidth;
mouseYEndPoint = window.innerWidth;
mouseXRange = mouseXEndPoint - mouseXStartPoint;
}
window.addEventListener('mousemove', mouseMove);
window.addEventListener('resize', windowResize);