<html>
<head>
    <style>
#div{width:50px;height:50px;background:red;position:absolute;top:50px;left:50px;}
#div2{width:50px;height:50px;background:green;position:absolute;top:100px;left:300px;}
    </style>
    <script>
window.onload = function () {
    move('div', +10, 300);
    move('div2', -10, 50);
};function move(id, offset, range) {
    var element = document.getElementById(id);
    var timer = setInterval(function () {
        if (element.style.left === range + 'px') {
            clearInterval(timer);
        }
        element.style.left = element.offsetLeft + offset + "px";
    }, 300);
}
    </script>
</head>
<body>
    <div id="div"></div>
    <div id="div2"></div>
</body>
</html>