Forum Moderators: open

Message Too Old, No Replies

Javascript image flipper / swapper / switcher

Simply changes an img every X seconds...?

         

JAB Creations

1:24 am on Jul 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm looking for a JS that will simply change the url of an img every X amount of seconds. Instead of throwing this in to flash I'd like to achieve this with JS. Anyone seen this JS anywhere?

wasproject

3:50 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



Hi JAB_Creations.

I have found one recently, but I took out the url array and loop that takes care of the url swapping, since I only needed one url.
I have too sign off for the weekend, so I am just giving you the code I got left and leave it to you to put the url swapping functionality back in.
Oh yeah, I found it via an ordinary search for 'image swapping javascript'.


var dimages=new Array();
for (i=0; i<5; i++){
dimages[i]=new Image();
dimages[i].src="img/promo1/image"+(i+1)+".gif";
}
var curImage=-1;
function swapPicture(){
var nextImage=curImage+1;
if (nextImage>=5) nextImage=0;
target=document.getElementById("myImage");
target.src=dimages[nextImage].src;
curImage=nextImage;
setTimeout("swapPicture()", 3000);
}
setTimeout("swapPicture()", 3000);

You might also use the below code amending this line:

msgs[count]="<a href=\"path.htm\" title=\"link to Contact\">"+msgs[count]+"</a>";
in particular.


var msgs=new Array("Join the Forum","Apply for newsletters","Contact us now");
var count=0;
var timer=1000;
document.write("<div id=\"msg\" ></div>");
function SlideText(){
if (count>=3) count=0;
msgs[count]="<a href=\"path.htm\" title=\"link to Contact\">"+msgs[count]+"</a>";
var enigma=(document.all)? msg:document.getElementById("msg");
enigma.innerHTML=msgs[count];
count=count+1;
setTimeout("SlideText()",timer);
timer=timer+1000;
}
setTimeout("SlideText()",timer);

I'll return on Monday to find out how you got on and whether you need some extra assistance.

Good luck.

JAB Creations

9:24 pm on Jul 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I found some good though somewhat extensive examples at the following url... [dyn-web.com...]

I'll take a look at the code a little later myself as time is not a luxury right now. :-\