I'm currently working on a jQuery function that operates on the mousemove event. The goal is to have two images - one main image and one shadow image, with the shadow image reflecting movement based on mouse position. While everything is functioning properly, I am looking for a way to pause the mousemove event when hovering over the main image, only to resume once the mouse is released from the image. Is there a method to achieve this? You can visit the project at this link -
HTML
<div style="width:100%">
<img id="shadow-img" style="position:absolute;"src="./assets/img/slsshadow.jpg"></img>
<img id="center-img" style="position:absolute;left:50%;top:50%;margin-left:-204px;margin-top:-204px" src="./assets/img/slslogo.jpg"></img>
</div>
jQuery
(function() {
var shadowImg = document.getElementById('shadow-img');
var centerImg = document.getElementById('center-img');
document.onmousemove = handleMouseMove;
function handleMouseMove(event) {
var center = {
x : centerImg.getBoundingClientRect().left + 204,
y : centerImg.getBoundingClientRect().top
};
var shadowPos = {
x : (1.8 * center.x) - event.pageX,
y : (2.2 * center.y) - event.pageY,
};
shadowImg.style.transform = 'translate(' + shadowPos.x + 'px,' + shadowPos.y +'px)';
};
})();