The given formula arranges the contents of the container according to the mouse movement.. the problem was in the size of the image, and in the fact that approaching along the x and y axes from different sides, the arrangement was calculated differently.
const zoomEffect = (event: any) => {
setZoomMode(true);
const xa = event.pageX-containerRef.current.offsetLeft;
const xb = containerRef.current.offsetWidth;
const xc = zoomRef.current?.getBoundingClientRect().width;
const ya = event.pageY-containerRef.current.offsetTop;
const yb = containerRef.current.offsetHeight;
const yc = zoomRef.current?.getBoundingClientRect().height;
setMouseCoords({
x: xc ? -(xa)/(xb/((xc)-xb)) : 0,
y: yc ? -(ya)/(yb/((yc)-yb)) : 0,
});
};
<div ref={conteinerRef} onMouseMove={zoomEffect}>
<div style={{
left: mouseCoords.x,
top: mouseCoords.y,
}}>
<Img ref_={zoomRef} />
</div>}
</div>