const cursorDiv = document.createElement('div'); cursorDiv.style.position = 'absolute';…
- User
const cursorDiv = document.createElement('div'); cursorDiv.style.position = 'absolute'; cursorDiv.style.width = '10px'; // Width of the cursor cursorDiv.style.height = '10px'; // Height of the cursor cursorDiv.style.backgroundColor = 'red'; // Color of the cursor cursorDiv.style.borderRadius = '50%'; // Make it circular cursorDiv.style.pointerEvents = 'none'; // Prevent interactions document.body.appendChild(cursorDiv); // Update cursor position based on touchmove event document.addEventListener('touchmove', (event) => { const touch = event.touches[0]; // Get the first touch point cursorDiv.style.left =
${touch.clientX}px; cursorDiv.style.top =${touch.clientY}px; }); I want it an image not a colored dot. If thr current link is website.com/x, the image link should be website.com/janko.png - Assistant
To use an image instead of a colored dot for your custom cursor, you just need to set the
cursorDivto have a background image instead of a background color. Below is the updated code:const cursorDiv = document.createElement('div'); cursorDiv.style.position = 'absolute'; cursorDiv.style.width = '20px'; // Customize the width of the cursor image cursorDiv.style.height = '20px'; // Customize the height of the cursor image cursorDiv.style.backgroundImage = 'url(https://website.com/janko.png)'; // Set the image for the cursor cursorDiv.style.backgroundSize = 'contain'; // Ensure the image is scaled properly cursorDiv.style.backgroundRepeat = 'no-repeat'; // Prevent the image from repeating cursorDiv.style.pointerEvents = 'none'; // Prevent interactions document.body.appendChild(cursorDiv); // Update cursor position based on touchmove event document.addEventListener('touchmove', (event) => { const touch = event.touches[0]; // Get the first touch point cursorDiv.style.left = `${touch.clientX - cursorDiv.clientWidth / 2}px`; // Center cursor image on touch point cursorDiv.style.top = `${touch.clientY - cursorDiv.clientHeight / 2}px`; // Center cursor image on touch point });