Skip to content

Commit

Permalink
feat: add cursor style
Browse files Browse the repository at this point in the history
  • Loading branch information
valcosmos committed Oct 20, 2024
1 parent fc53a39 commit faf548b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/BackgroundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Canvas, useFrame } from '@react-three/fiber'
import { motion } from 'framer-motion'
import dynamic from 'next/dynamic'
import React, { useRef } from 'react'
import Cursor from './Cursor'
import { pointsInner, pointsOuter } from './utils'

const ScrollTopAndComment = dynamic(() => import('./ScrollTopAndComment'), { ssr: false })
Expand Down Expand Up @@ -60,6 +61,7 @@ function Point({ position, color }) {
export default function BackgroundWrapper({ children }: { children: React.ReactNode }) {
return (
<div className="h-screen w-screen">
<Cursor />
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
Expand Down
28 changes: 28 additions & 0 deletions components/Cursor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use client'

import { motion } from 'framer-motion'
import React, { useEffect, useState } from 'react'

export default function Cursor() {
const [position, setPosition] = useState({ x: 0, y: 0 })

useEffect(() => {
const mouseMove = (e) => {
setPosition({ x: e.clientX, y: e.clientY })
}

window.addEventListener('mousemove', mouseMove)

return () => {
window.removeEventListener('mousemove', mouseMove)
}
}, [])

return (
<motion.div
className="fixed z-[999] size-12 rounded-full border border-black dark:border-white"
animate={{ x: position.x + 10, y: position.y + 10 }}
>
</motion.div>
)
}

0 comments on commit faf548b

Please sign in to comment.