I want to attach to cursor an element(blue circle) and leave ability to click on that circle. To display this circle correctly - cursor is always in center of circle - I disabled events using pointer-events: none
. As a result it blocks ability to click on that circle. Is it possible to block mousemove events, but leave click events?
const CURSOR_SIZE = 30;
const field = document.querySelector('#field');
const cursor = document.querySelector('#cursor');
field.onmousemove = (event) => {
const { offsetX, offsetY } = event;
const shiftX = offsetX - CURSOR_SIZE;
const shiftY = offsetY - CURSOR_SIZE;
updateCursorPosition(shiftX, shiftY);
}
function updateCursorPosition(x, y) {
cursor.style.top = `${y}px`;
cursor.style.left = `${x}px`;
}
cursor.onclick = () => {
console.log('handle click')
}
body {
margin: 0;
background-color: #e6ffff;
}
#field {
position: relative;
width: 100vw;
height: 100vh;
}
#cursor {
position: absolute;
width: 60px;
height: 60px;
border-radius: 50%;
border: solid 2px #00cccc;
background-color: #00ffff;
pointer-events: none;
}
<div id="field">
<div id="cursor"></div>
<div>