To begin, change the position of the image or element you want to follow the cursor to absolute.
#image {
position:absolute;
}
Next, set the left and top positions of the image to match the cursor position using the mousemove event. Here's an example using jQuery:
$(document).mousemove(function(e){
$("#image").css({left:e.pageX, top:e.pageY});
});
You can also achieve this with vanilla JavaScript:
document.addEventListener('mousemove', function(e) {
let body = document.querySelector('body');
let image = document.getElementById('image');
let left = e.offsetX;
let top = e.offsetY;
image.style.left = left + 'px';
image.style.top = top + 'px';
});
I hope this explanation helps you with your task.