Skip to content

Commit d6ede89

Browse files
authored
Merge pull request #200 from TheCoderAdi/feat/added-cursor-animation
Adding cursor following animation
2 parents 16170ad + 0b5e7d0 commit d6ede89

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

apps/web/app/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Metadata } from "next";
33
import { Inter } from "next/font/google";
44
import { Navbar } from "../components/Navbar";
55
import GlobalWrapper from "../components/common/GlobalWrapper";
6+
import CursorFollower from "../components/common/CursorFollower";
67

78
const inter = Inter({ subsets: ["latin"] });
89

@@ -19,6 +20,7 @@ export default function RootLayout({
1920
return (
2021
<html lang="en">
2122
<body className={inter.className}>
23+
<CursorFollower />
2224
<GlobalWrapper>
2325
<Navbar />
2426
{children}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use client";
2+
import { useEffect, useRef } from "react";
3+
4+
const CursorFollower = () => {
5+
const cursorRef = useRef<HTMLDivElement>(null);
6+
7+
useEffect(() => {
8+
const moveCursor = (e: MouseEvent) => {
9+
if (cursorRef.current) {
10+
cursorRef.current.style.transform = `translate(${e.clientX}px, ${e.clientY}px)`;
11+
}
12+
};
13+
14+
document.addEventListener("mousemove", moveCursor);
15+
return () => document.removeEventListener("mousemove", moveCursor);
16+
}, []);
17+
18+
return (
19+
<div
20+
ref={cursorRef}
21+
className="fixed z-[50] top-0 left-0 w-6 h-6 bg-white/70 opacity-75 rounded-full pointer-events-none shadow-[0_0_10px_#fff] transition-transform duration-75 ease-out"
22+
/>
23+
);
24+
};
25+
26+
export default CursorFollower;

0 commit comments

Comments
 (0)