-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (28 loc) · 979 Bytes
/
script.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
const body = document.querySelector('body');
const cursor = document.querySelector('#cursor');
const toggle = document.querySelector('#toggle');
const Labels = {
LIGHT_OFF: 'Turn Lights off!',
LIGHT_ON: 'Turn Lights on!',
}
const isDark = () => body.classList.contains('dark');;
function positionElement(e) {
const mouseY = e.layerY;
const mouseX = e.layerX;
cursor.style.transform = `translate3d(${mouseX}px, ${mouseY}px, 0)`;
}
window.addEventListener('mousemove', positionElement);
window.addEventListener('touchstart', positionElement);
window.addEventListener('touchmove', positionElement);
function toggleDarkMode() {
if (isDark()) {
body.classList.remove('dark');
toggle.innerText = Labels.LIGHT_OFF
}
else {
body.classList.add('dark');
toggle.innerText = Labels.LIGHT_ON
}
}
toggle.innerText = Labels.LIGHT_ON;
toggle.addEventListener('click', toggleDarkMode);