I’m working on a cursor button for a website that changes the style of the cursor whenever the button is active (I’m using an svg file). Right now I have it to where it changes the style of the cursor, however whenever I hover over a button it uses the default pointer.
Is there any way I can make the pointer have a different style as well when the button is on, so that whenever they hover over something clickable the pointer matches the cursor?
This is what I’m using for the cursor function
useEffect(() => {
console.log('Cursor icon:', cursorIcon); // Log the cursor icon
const body = document.body;
if (isCursorButtonPressed) {
body.style.cursor = `url(${cursorIcon}), auto`;
} else {
body.style.cursor = 'auto';
}
}, [isCursorButtonPressed, cursorIcon]);
and then I just call it on the css file as
.cursor-button.active {
cursor: url('${cursorIcon}'), auto;
}
2
Answers
Dynamically add a class to the body when the button is pressed and use that class in your CSS selector.
CSS
If you have many custom cursor buttons. Give unique name to each custom cursor class.
Here is my solution.
Two points to note
code
stackblitz