I try to animate an element in JavaScript. My goal is to move the element from its current position to the cursor. I can't figure out why the element is not moving as expected. The X-translation is OK, but the Y-translation is in the wrong direction.
document.addEventListener('click', function(event) {
document.getElementById("el").animate([
{ top: (event.clientY)+'px' },
{ left: (event.clientX)+'px' }
],
{
// timing options
duration: 1000,
fill: 'forwards',
});
})
#el {
position:absolute;
top: 10px;
left: 10px;
background-color: cyan;
}
<div id="el">Click to move</div>