Skip to content

Commit 9c2b64f

Browse files
committed
refactor: Move custom cursor script from index page to base layout.
1 parent 7accf1d commit 9c2b64f

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

src/layouts/BaseLayout.astro

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,41 @@ const fullImageUrl = image.startsWith('http') ? image : `${siteUrl}${image}`;
7676
}
7777
});
7878
</script>
79+
80+
<script>
81+
import { gsap } from 'gsap';
82+
83+
// Custom cursor
84+
const cursorDot = document.querySelector('.cursor-dot');
85+
const cursorOutline = document.querySelector('.cursor-outline');
86+
87+
if (cursorDot && cursorOutline && window.matchMedia('(hover: hover)').matches) {
88+
window.addEventListener('mousemove', (e) => {
89+
gsap.to(cursorDot, {
90+
x: e.clientX,
91+
y: e.clientY,
92+
duration: 0.1,
93+
});
94+
gsap.to(cursorOutline, {
95+
x: e.clientX,
96+
y: e.clientY,
97+
duration: 0.3,
98+
});
99+
});
100+
101+
// Expand cursor on interactive elements
102+
document.querySelectorAll('a, button, [data-cursor]').forEach((el) => {
103+
el.addEventListener('mouseenter', () => {
104+
gsap.to(cursorOutline, { scale: 2, opacity: 1, duration: 0.3 });
105+
gsap.to(cursorDot, { scale: 0.5, duration: 0.3 });
106+
});
107+
el.addEventListener('mouseleave', () => {
108+
gsap.to(cursorOutline, { scale: 1, opacity: 0.5, duration: 0.3 });
109+
gsap.to(cursorDot, { scale: 1, duration: 0.3 });
110+
});
111+
});
112+
}
113+
</script>
79114
</body>
80115
</html>
81116

src/pages/index.astro

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -384,34 +384,4 @@ const supportLinks = [
384384
});
385385
});
386386

387-
// Custom cursor
388-
const cursorDot = document.querySelector('.cursor-dot');
389-
const cursorOutline = document.querySelector('.cursor-outline');
390-
391-
if (cursorDot && cursorOutline && window.matchMedia('(hover: hover)').matches) {
392-
window.addEventListener('mousemove', (e) => {
393-
gsap.to(cursorDot, {
394-
x: e.clientX,
395-
y: e.clientY,
396-
duration: 0.1,
397-
});
398-
gsap.to(cursorOutline, {
399-
x: e.clientX,
400-
y: e.clientY,
401-
duration: 0.3,
402-
});
403-
});
404-
405-
// Expand cursor on interactive elements
406-
document.querySelectorAll('a, button, [data-cursor]').forEach((el) => {
407-
el.addEventListener('mouseenter', () => {
408-
gsap.to(cursorOutline, { scale: 2, opacity: 1, duration: 0.3 });
409-
gsap.to(cursorDot, { scale: 0.5, duration: 0.3 });
410-
});
411-
el.addEventListener('mouseleave', () => {
412-
gsap.to(cursorOutline, { scale: 1, opacity: 0.5, duration: 0.3 });
413-
gsap.to(cursorDot, { scale: 1, duration: 0.3 });
414-
});
415-
});
416-
}
417387
</script>

0 commit comments

Comments
 (0)