I've made a custom cursor on my react app, but I would like to animate it when the user click. Like to decrease the size or something like that. The cursor is in a components that I've call on my Index.js file. I don't know how to make a addlisterner element who change the class of the cursor. I'm new in web development if someone wants to help me, it will be grate :)
Here's the Custom Cursor component :
import React, { useRef } from 'react'
function CustomCursor() {
const cursorRef = useRef(null)
React.useEffect(() => {
document.addEventListener('mousemove', (event)=> {
const {clientX, clientY} = event;
const mouseX = clientX - cursorRef.current.clientWidth /2;
const mouseY = clientY - cursorRef.current.clientHeight /2;
cursorRef.current.style.transform = `translate3d(${mouseX}px, ${mouseY}px, 0)`
})
}, [])
return ( <div className='custom-cursor' ref={cursorRef}></div> ) }
export default CustomCursor
The css class in detail :
.custom-cursor {
z-index: 9999;
border-radius: 50%;
width: 20px;
height: 20px;
background-color: #8c8c8cb8;
pointer-events: none;
overflow: hidden;
transform: translate(-50%, -50%);
position: fixed;
}
I really don't know what to try :/