View Full Version : how can i... swapimage IF image = 'anyof4.gif' ??

09-28-2005, 09:56 PM
first post, i read the must-reads, i did a little searching.
i didnt expect to see this topic anywhere anyways.. but picture this:

ive got 4 images that i can change using onClick.
lets just call them 1.gif - 4.gif.

then i have arrow buttons... left and right, that control the image.

say the default picture is 1.gif, and it loads when the page loads.

if i click my RIGHT arrow, 1.gif changes to 2.gif.
now i want to be able to click the SAME right arrow... and have 2.gif change to 3.gif, instead of just staying as 2.gif.

and if i were to click on the left arrow now... it would go back to 2.gif. click left again.... 1.gif... left again... 4.gif, and so on.

so i guess in a nutshell... i want my arrows to swap my image to a certain new image, depending on what the image currently is.
(and note: i know i can do this with layers... but it gets to be an insane amount of layers, and firefox shifts the layers down a few pixels... and i cant have that, lol..... and i could also just change the page, with the same exact layout.. but i need it seemless... im pretty picky :D)

so im assuming i will need some sort of if statements... i guess im just a little too new to java to throw it all together.
hopefully this is possible, and i greatly appreciate anyones help.
thanks :D

09-28-2005, 11:14 PM
I think this script can help you:

Picture=new Array;
function ShiftLeft(){
if (P=-1){P+=Picture.length}
function ShiftRight(){
if (P>Picture.length){P-=Picture.length}
The picture must then be named and initialised

<Img ID="picture" Src="1.jpg">
and then use
onClick="ShiftLeft()" on your left button and
onClick="ShiftRight()" on your right button.
By inserting the pictures into an array it doesn't matter what the names of the pictures are as they are assigned a number this way.

if you then want to add pictures to the list you just add an item to the array:

09-29-2005, 02:15 AM
wow... thanks!
you are definitely smarter and cooler than me. :D

ok but yea... it didnt QUITE work.
i plugged that pile of goodness into a brand new page
i whipped up real quick...
and well, here... play with it.


theres a few SLIGHT modifications i made... left and right are now up and down,
respectively. you'll understand why if u take a look... i also renamed the functions... thats just for me though.
but i tried it without changing anything, and the effect was the same.

i'm pretty sure it has something to do with the part about "if p=-1."
i might try changin it to "if p<0" or something... i dunno.
but i need to be able to cycle thru the pictures in each direction.. continuously up... or down... or up down down down up up down up up up up down...
it will probably further complicate the functions, but its good to learn some stuff.
thanks again lerura... 'preciate anything else you or anyone can give me.

* EDIT *

ok... changing that if statement did help.
it left me with a tiny problem where it wouldnt load the 1st pic each time u got back around to it when clicking up. so that was weird, but i changed the variables in the array and started them at 1, instead of 0, which fixed that.
but now... it takes 2 clicks to get from 4.jpg, back to 1.jpg...
as well as going in reverse from 1 to 4.
play with it here: http://www.starrtrax.net/iloveCF/almost.htm

09-29-2005, 03:03 AM
i made to errors:

in ShiftUp change "if (P=-1)" to "if (P<0)"
in ShiftDown change "if (P>Picture.length)" to "if (P>Picture.length-1)"

09-29-2005, 03:40 AM
i cant thank you enough.
gah... now im excited..
gonna go mess with my site.

i may be back here to ask my original question again... cuz i may have another
purpose for it.
uhm... so if anyone knows how to make a link do something based solely on which image is currently being displayed somewhere... i could still use that info.

i could come up with a more in-depth explanation or example site if need be.

thanks again lerura.. im pronouncing that like la-roar-uh...
maybe your name is laura and someone stutterd one day and called you laraura...??? maybe ur not female... dunno. was fun to think about tho.
:eek: laters.

09-29-2005, 03:49 AM
i have had many guesses on my username.
that's just the initial letters of my 6 names.

and for your issue. if u can give me a little more information on what will use it for then we can try work something out tomorrow.