I am working on a piece of code that involves moving an image across the screen. The current code I have is:
<script type="text/javascript">
var animate, left=0, imgObj=null;
function init(){
imgObj = document.getElementById('myImage');
imgObj.style.position= 'absolute';
imgObj.style.top = '240px';
imgObj.style.left = '-300px';
imgObj.style.visibility='hidden';
moveRight();
}
function moveRight(){
left = parseInt(imgObj.style.left, 10);
if (10 >= left) {
imgObj.style.left = (left + 5) + 'px';
imgObj.style.visibility='visible';
animate = setTimeout(function(){moveRight();},20);
} else {
stop();
}
}
function stop(){
clearTimeout(animate);
}
window.onload = function() {init();};
</script>
<img id="myImage" src="http://newsxpressmedia.com/files/radar-simulation-files/radar007339.Gif" style="margin-left:170px;" />
The current functionality moves the image from the left side to the center of the screen. However, I would like it to start at the top left corner and move all the way to the right top border, continuously looping back. Unfortunately, changing the values to 0 only made the image static in its position.
I am also interested in adding more images to create a continuous sliding effect from left to right. How can I modify the code to achieve this?