I am trying to move the ball to the point where the mouse clicks. The function is logging the X and Y but not moving the ball. What am I missing here?
Typescript react component
const PlayArea = () => {
let top = 'inherit';
let left = 'inherit';
document.addEventListener("click", function(e){
console.log((e.clientX + 25) + 'px')
top = (e.clientY - 25) + "px";
console.log(top)
left = e.clientX - 25 + "px";
});
return (
<>
<div className="ball" style={{ transform: `top ${top}, left ${left}` }}></div>
</>
);
};
export default PlayArea;
css
.ball {
height: 100px;
width: 100px;
border-radius: 50%;
background-color: #0b8027;
position:absolute;
}