-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (55 loc) · 1.93 KB
/
Copy pathscript.js
File metadata and controls
69 lines (55 loc) · 1.93 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const lenis = new Lenis({
lerp: 0.12,
wheelMultiplier: 1,
infinite: false,
smoothWheel: true
});
function raf(time) {
lenis.raf(time);
requestAnimationFrame(raf);
}
requestAnimationFrame(raf);
const backTop = document.getElementById('back-top');
lenis.on('scroll', (e) => {
backTop.classList.toggle('visible', e.scroll > 300);
});
backTop.addEventListener('click', () => {
lenis.scrollTo(0, { duration: 1.2 });
});
const cursor = document.getElementById('cursor');
let mouseX = -100, mouseY = -100;
let cursorX = -100, cursorY = -100;
window.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
function animateCursor() {
let dt = 0.15;
cursorX += (mouseX - cursorX) * dt;
cursorY += (mouseY - cursorY) * dt;
cursor.style.left = `${cursorX}px`;
cursor.style.top = `${cursorY}px`;
requestAnimationFrame(animateCursor);
}
animateCursor();
const hoverElements = document.querySelectorAll('.input-hover, a, button, .project-card, .avatar');
hoverElements.forEach(el => {
el.addEventListener('mouseenter', () => cursor.classList.add('hovered'));
el.addEventListener('mouseleave', () => cursor.classList.remove('hovered'));
});
document.addEventListener('mouseleave', () => {
cursor.style.opacity = '0';
});
document.addEventListener('mouseenter', () => {
cursor.style.opacity = '1';
});
const reveals = document.querySelectorAll('.reveal');
const io = new IntersectionObserver((entries) => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('in');
io.unobserve(e.target);
}
});
}, { threshold: 0.1 });
reveals.forEach(el => io.observe(el));