Those days I watch in youtube great video how to create custom cursor CSS and JS.
So I wrote this code in ReactJS and create almost similar custom cursor effect.But there and small bug when user scroll (without move mouse only scroll) my custom cursor not moving.
Please help how to solve this issue.
state = {
xMain: 0,
yMain: 0,
expand: false
};
componentDidUpdate() {
if (this.state.expand) {
setTimeout(() => {
this.setState({ expand: false });
}, 500);
}
}
handleMouseMove = e => {
const { pageX, pageY } = e;
this.setState({
xMain: pageX,
yMain: pageY
});
};
expandCursor = () => {
this.setState({
expand: true
});
};
render = () => {
const { xMain, yMain } = this.state;
return (
<div
className="container"
onClick={this.expandCursor}
onMouseMove={e => this.handleMouseMove(e)}
>
<div
className={this.state.expand ? "cursor expand" : "cursor"}
style={{
left: xMain,
top: yMain
}}
/>
</div>
);
};