-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (44 loc) · 1.58 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
let canvas = document.getElementById("canvas");
let cursor = document.getElementById("cursor");
let fistCursor = new Image;
let pointerCursor = new Image;
fistCursor.src = "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/160/microsoft/310/raised-fist_270a.png";
pointerCursor.src = "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/160/microsoft/310/backhand-index-pointing-up_1f446.png";
let ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let cursorSize = 50;
let currentCursor = fistCursor;
// clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// draw cursor image
ctx.drawImage(currentCursor, 0, 0, cursorSize, cursorSize);
window.addEventListener("mousemove", (e) => {
let x = e.clientX;
let y = e.clientY;
let cursorXpos = x - cursorSize * 30 / 100;
let cursorYpos = y - cursorSize * 10 / 100;
// clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// draw cursor image
ctx.drawImage(currentCursor, cursorXpos, cursorYpos, cursorSize, cursorSize);
});
window.addEventListener("resize", (e) => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
let links = document.querySelectorAll("a");
links.forEach(link => {
link.addEventListener("mouseenter", (e) => {
usePointerCursor();
});
link.addEventListener("mouseleave", (e) => {
useFistCursor();
});
});
const useFistCursor = () => {
currentCursor = fistCursor;
}
const usePointerCursor = () => {
currentCursor = pointerCursor;
}