-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCursor.jsx
61 lines (51 loc) · 1.35 KB
/
Cursor.jsx
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
import { useEffect, useState } from 'react';
import { motion } from 'framer-motion';
import './Cursor.css'
import Button from '../../components/Button';
function App() {
const [mousePosition, setMousePosition] = useState({
x: 0,
y: 0
});
const [cursorVariant, setCursorVariant] = useState("default");
useEffect(() => {
const mouseMove = e => {
setMousePosition({
x: e.clientX,
y: e.clientY
})
}
window.addEventListener("mousemove", mouseMove);
return () => {
window.removeEventListener("mousemove", mouseMove);
}
}, []);
const variants = {
default: {
x: mousePosition.x - 16,
y: mousePosition.y - 16,
},
text: {
height: 150,
width: 150,
x: mousePosition.x - 75,
y: mousePosition.y - 75,
backgroundColor: "white",
mixBlendMode: "difference"
}
}
const textEnter = () => setCursorVariant("text");
const textLeave = () => setCursorVariant("default");
return (
<div className="App">
<h1 onMouseEnter={textEnter} onMouseLeave={textLeave} className='title'>Hello Friends</h1>
<motion.div
className='cursor'
variants={variants}
animate={cursorVariant}
/>
<Button className="w-20 h-20 text-white bg-black flex item-center" next="/pagetrans"/>
</div>
);
}
export default App;