<a id="imageurl" name="imageurl"><img src="Rotating1" id="Rotating1" border="0" alt="Rotating1" name="Rotating1" /></a>
<script language="javascript" type="text/javascript">
function RotateImages(Start)
{
var a = new Array("1.jpg","2.jpg","3.jpg", "4.jpg");
var c = new Array("url1", "url2", "url3", "url4");
var b = document.getElementById('Rotating1');
var d = document.getElementById('imageurl');
if(Start>=a.length)
Start=0;
b.src = a[Start];
d.href = c[Start];
window.setTimeout("RotateImages(" + (Start+1) + ")",3000);
}
RotateImages(0);
</script>
views:
62answers:
2
+1
A:
The return value of setTimeout can be passed to cancelTimeout to stop the rotation. You might save it to a variable, then cancel the timeout on MouseIn and restart it on MouseOut.
Sparr
2010-08-27 06:54:33
That is sounding good, but I am incapable of implementing it, do you have the time to post a code snippet or example? I really know nothing of javascript, this is borrowed code that I have only modified to be xhtml 1.0 transitional for a site I am hand coding.
Mike
2010-08-27 06:58:24
+1
A:
Change your code as Follows:
<a id="imageurl" name="imageurl"><img src="Rotating1" id="Rotating1" border="0" alt="Rotating1" name="Rotating1" onmouseover="StopRotation();" onmouseout="RotateImages();"/></a>
<script language="javascript" type="text/javascript">
var currentImage = -1;
function RotateImages()
{
var a = new Array("1.jpg","2.jpg","3.jpg", "4.jpg");
var c = new Array("url1", "url2", "url3", "url4");
var b = document.getElementById('Rotating1');
var d = document.getElementById('imageurl');
currentImage++;
if(currentImage>= a.length)
currentImage=0;
b.src = a[currentImage];
d.href = c[currentImage];
rotator = window.setTimeout("RotateImages(" + (currentImage+1) + ")",3000);
}
function StopRotation()
{
window.clearTimeout(rotator);
}
RotateImages();
</script>
- added Function "
StopRotation" - added
onmouseoverandonmouseout-Events to the Image Tag - Rotation continues at the current Image.
Dratir
2010-08-27 07:08:28
Wow, perfect! The only other thing I could ask at this point would be that the rotation continues instead of resetting to the first image. Otherwise this will be what I use on the site.
Mike
2010-08-27 07:26:33
Thank you so much, you have helped me immensely, I set var currentImage = 0 to -1 instead so it starts on the first specified image in the array.
Mike
2010-08-27 08:04:57
ah, yeah, i thougth about this aswell.Test it and dont't forget to accept the solution if it works! :-)
Dratir
2010-08-27 08:13:02