The keyboard controls the movement of the div. Why is it much faster to move to the right than to the left? Going down is much faster than going up?

        var oDiv = document.getElementById("div1"),
            ev = ev || event;

        document.onkeydown = function (ev) {
            var pos=getPos(oDiv);
            switch (ev.keyCode) {
                case 37:
                    oDiv.style.left = oDiv.offsetLeft - 10 + "px";
                    break;
                case 38:
                    oDiv.style.top = oDiv.offsetTop - 10 + "px";
                    break;
                case 39:
                    oDiv.style.left = oDiv.offsetLeft + 10 + "px";
                    break;
                case 40:
                    oDiv.style.top = oDiv.offsetTop + 10 + "px";
                    break;
           
            }
        }
        
        
  divrelativeabsolute.....?   
  ,position:relative,bodymarginpadding0,~o()o
     
Mar.02,2021

took a look. It seems to be the reason why style.left and offsetLeft are not equal.
you should have no problem setting the inner and outer margins of the parent element to 0.

Menu