-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcursor.js
More file actions
50 lines (46 loc) · 1.43 KB
/
Copy pathcursor.js
File metadata and controls
50 lines (46 loc) · 1.43 KB
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
(function () {
if ('ontouchstart' in window || navigator.maxTouchPoints > 0) return;
const dot = document.createElement('div');
const ring = document.createElement('div');
dot.id = 'cursor-dot';
ring.id = 'cursor-ring';
document.body.appendChild(dot);
document.body.appendChild(ring);
document.documentElement.style.setProperty('cursor', 'none', 'important');
const style = document.createElement('style');
style.textContent = '* { cursor: none !important; }';
document.head.appendChild(style);
let tx = 0, ty = 0;
let rx = 0, ry = 0;
let started = false;
document.addEventListener('mousemove', e => {
tx = e.clientX; ty = e.clientY;
dot.style.left = tx + 'px';
dot.style.top = ty + 'px';
if (!started) {
rx = tx; ry = ty;
dot.style.opacity = '1';
ring.style.opacity = '0.6';
started = true;
}
});
(function animateRing() {
rx += (tx - rx) * 0.15;
ry += (ty - ry) * 0.15;
ring.style.left = rx + 'px';
ring.style.top = ry + 'px';
requestAnimationFrame(animateRing);
})();
document.querySelectorAll('a, button').forEach(el => {
el.addEventListener('mouseenter', () => {
ring.style.width = '44px';
ring.style.height = '44px';
ring.style.opacity = '1';
});
el.addEventListener('mouseleave', () => {
ring.style.width = '28px';
ring.style.height = '28px';
ring.style.opacity = '0.6';
});
});
})();