if i have an animated gif go left to right, how do i switch the gif to go from right to left via javascript? I have it working but I don't know how to stop the gif and switch it to another gif to go from right to left. it just loops the same gif from left to right and back to left. The reverse gif is ani_catrev.gif.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cat running</title>
<style type="text/css">
#container {
background:url(catBack1200.jpg) no-repeat;
width:1200px;
height:440px;
}
#catbox {
position:absolute;
top:330px;
left:10px;
}
</style>
<script type="text/javascript">
var switchDirection = false;
function doAnimation() {
var catbox = document.getElementById("catbox");
var currentLeft = catbox.offsetLeft;
var newLocation;
if (switchDirection == false)
{
newLocation = currentLeft + 5;
if (currentLeft >= 1000)
{
switchDirection = true;
}
}
else
{
newLocation = currentLeft - 5;
if (currentLeft <= 0)
{
switchDirection = false;
}
}
catbox.style.left = newLocation + "px";
}
</script>
</head>
<body onload="setInterval(doAnimation, 10)">
<div id="container">
<div id="catbox">
<img src="ani_cat.gif" id="cat" width="100" height="60" alt="busy kitty" />
</div>
</div>
</body>
</html>