I'm Having trouble to center the default mouse cursor inside a circle that follows the mouse cursor
see this image
// Create an html element and append to body
const dpkCursor = document.createElement("div");
dpkCursor.classList.add("dpkCursor");
document.body.appendChild(dpkCursor);
// Fuction that create circle to follow the cursor
function initCursor(speedOption = 0.25) {
let dpkCursorMouse = { x: -100, y: -100 };
let dpkCursorPos = { x: 0, y: 0 };
let speed = speedOption;
window.addEventListener("mousemove", (e) => {
dpkCursorMouse.x = e.x;
dpkCursorMouse.y = e.y;
});
const updatePosition = () => {
dpkCursorPos.x += (dpkCursorMouse.x - dpkCursorPos.x) * speed;
dpkCursorPos.y += (dpkCursorMouse.y - dpkCursorPos.y) * speed;
dpkCursor.style.transform = `translate(${dpkCursorPos.x}px ,${dpkCursorPos.y}px)`;
};
function loop() {
updatePosition();
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
}
initCursor()
