in this below example move image from original position to right.
we use setTimeout and clearTimeout to start and stop image animate.
html input button click method handle.
<script type = "text/javascript">
var getimage = null;
var animate ;
function init() {
getimage = document.getElementById('myImage');
getimage.style.position= 'relative';
getimage.style.left = '0px';
}
function move() {
getimage.style.left = parseInt(getimage.style.left) + 10 + 'px';
animate = setTimeout(move,60); // call move in 60msec
}
function stop() {
clearTimeout(animate);
getimage.style.left = '0px';
}
window.onload = init;
</script>
<div>
<img id = "myImage" src = "hello.png" />
<p>Click the buttons below to handle animation</p>
<input type = "button" value = "Start" onclick = "move()" />
<input type = "button" value = "Stop" onclick = "stop()" />
</div>