crop_rotate
Run
<!DOCTYPE html> <html> <style> #container { width: 100%; height: 100px; position: relative; background: yellow; } #animate { width: 50px; height: 50px; position: absolute; background-color: red; border-radius:50%; margin-top:20px; } </style> <body> <p><button onclick="myMove()">Click Me</button></p> <div id ="container" width=100% ;> <div id ="animate"></div> </div> <script> var id = null; function myMove() { var elem = document.getElementById("animate"); var container = document.getElementById("container"); var pos = 0; clearInterval(id); id = setInterval(frame, 5); function frame() { if (pos == container.getBoundingClientRect().width - 50) { clearInterval(id); } else { pos++; elem.style.left = pos + "px"; } } } </script> </body> </html>
Click Me