image cycling
- Started
- Last post
- 13 Responses
- quamb
um stuck and spent on searching.
i need 3 images to randomly cycle, though it seems all javascripts (I'm terrible at code) only allow for 1 cycling image per page.
i'd rather not use flash..
any advice/help?
cheers
- mitsu0
what do you mean by cycle? a continuous loop of all three images? or an event driven single loop?
- quamb0
3 seperate tags, each one to cycle randomly through 6 jpg files.
ie. i can only get 1 tag to cycle through the images, whilst the other 2 either:
a)dont work
b)cycle identically to the 1st
c)require a whole new javascript for each instance*sob* so simple, yet so time consuming
i need a coder friend
- mitsu0
name your imaes img1, img2, etc and then run this:
var i_ctr=0;
function fn_loop()
{
if(i_ctr<3)
{
i_ctr++;
my_img.src="images/img"+ictr+".g...
setTimeout("fn_loop()", 1000);
}
}
- quamb0
heya mitsu- thanks so much for your help!
though (sorry to be daft) how do I run the script? I've tried running fn_loop() though nothing happens...
doing something wrong?
- mitsu0
just call it in the body onload function:
onload='fn_loop()'
put your images in an images/ directory or just remove that from the string.
- quamb0
sorry mitsu, being so stupid here :(
though it won't work, i've tried running via onload='fn_loop90' in both and a simple
also checked the script to make sure its not clashing with my other scripts.
*sigh* any ideas to help this helpless nerd?
- mitsu0
no problem, try this to make it easier:
1.) first put your images in the same directory as the page this script is running on.
2.) make sure your images are named img1.gif, img2.gif, etc.
3.)change this line
my_img.src="images/img"+ictr+".g...to this:
my_img.src="img"+ictr+".gif";
honestly, it'd be better to set up an image preloader for this do you know how to do that?
- quamb0
hmm no luck.
they are already preloading if thats what you meant?
perhaps where the code is wrong? should i be using name="my_img" to call up the script?
- CAJTBr0
maybe you could post the url, quamb?
- mitsu0
what's the name of your images and how many do you have?
- quamb0
not online :(
sorry for being such a hassle.
though really, its a simple as wanting 3 images next to eachother, all randomly cycling through 6 jpgs.
pity im such a dum-ass
- quamb0
img1.jpg -> img6.jpg
i changed the code from gif to jpg obviously
and moved the files to the same folder as per requested
- xpedious0
http://www.xpedious.net/source/?…
^ tutorial i wrote, the actual tutorial part isn't written that well, but it has the final script at the end. easy to modify too.