Почему не работает? Вроде бы все верно тут?
window.onload = function () {
let field = document.getElementById('field')
let activeElement;
let offX = 0;
let offY = 0;
let mDown = function(e) {
console.log(e.target);
activeElement = e.target;
offY = e.offsetY;
offX = e.offsetX;
};
let mUp = function(e) {
activeElement = null;
};
let mMove = function(e) {
if(activeElement) {
activeElement.style.top = (e.clientY - offY) + 'px';
activeElement.style.left = (e.clientX - offX) + 'px';
}
};
field.addEventListener('mousedown', mDown);
field.addEventListener('mouseup', mUp);
field.addEventListener('mousemove',mMove)
}