Empaquetado simple y anotación de movimiento de movimiento.
var times = '';
function startMove(ele, targetObj, cb) {
let onOff = false;
clearInterval(times);
times = setInterval(() => {
for (let attr in targetObj) {
let tmpPos = parseInt(getPos(ele, attr));
console.log(tmpPos);
let speed = (targetObj[attr] - tmpPos) / 10;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if (tmpPos + speed == targetObj[attr]) {
onOff = true;
}
ele.style[attr] = tmpPos + speed + 'px';
}
if (onOff) {
clearInterval(times);
cb && cb();
}
}, 30)
}
function getPos(obj, attr) {
if (obj.currentStyle) {
return obj.currentStyle[attr];
} else {
return getComputedStyle(obj)[attr]
}
}