-
Notifications
You must be signed in to change notification settings - Fork 1
/
logic.js
81 lines (47 loc) · 1.89 KB
/
logic.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let pupils = document.getElementsByClassName("pupil")
let pupilArr = Array.from(pupils);
let pupilStartPoint = -75;
let PupilRange = 150;
let mouseXStartPoint = 0;
let mouseXEndPoint = window.innerWidth;
let currentXPostn = 0;
let fractionX = 0;
let mouseYEndPoint = window.innerHeight;
let currentYPostn = 0;
let fractionY = 0;
let shy = document.getElementsByClassName("shine")
let shyArr = Array.from(shy);
let shyStartPoint = -10;
let shyRange = 50;
let moo = document.getElementsByClassName("mouth")
let mooArr = Array.from(moo);
let mooStartPoint = -10;
let mooRange = 50;
const mouseMove = (event) => {
//console.log(`x value = ${event.clientX} & y value = ${event.clientY}`);
currentXPostn = event.clientX;
fractionX = currentXPostn/mouseXEndPoint;
currentYPostn = event.clientY;
fractionY = currentYPostn/mouseYEndPoint;
let pupilXCurrPostn = pupilStartPoint + (fractionX*PupilRange);
let pupilYCurrPostn = pupilStartPoint + (fractionY*PupilRange);
pupilArr.forEach((currPupil) => {
currPupil.style.transform = `translate(${pupilXCurrPostn}px , ${pupilYCurrPostn}px)`;
})
let shyXCurrPostn = shyStartPoint + (fractionX*shyRange);
let shyYCurrPostn = shyStartPoint + (fractionY*shyRange);
shyArr.forEach((currshy) => {
currshy.style.transform = `translate(${shyXCurrPostn}px , ${shyYCurrPostn}px)`;
})
let mooXCurrPostn = mooStartPoint + (fractionX*mooRange);
mooArr.forEach((currmoo) => {
currmoo.style.transform = `translateX(${mooXCurrPostn}px)`;
currmoo.style.width= `translateX(${fractionX*mooRange}px)`
})
}
const resize = (event) => {
mouseXEndPoint = window.innerWidth;
mouseYEndPoint = window.innerHeight;
}
window.addEventListener('mousemove', mouseMove);
window.addEventListener('resize', resize);