Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how can i... swapimage IF image = 'anyof4.gif' ??

    alright...
    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 )

    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
    Last edited by insidi0us; 09-28-2005 at 09:12 PM.

  • #2
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    904
    Thanks
    0
    Thanked 118 Times in 117 Posts
    I think this script can help you:
    Code:
    Picture=new Array;
    Picture[0]='1.jpg';
    Picture[1]='2.jpg';
    Picture[2]='3.jpg';
    Picture[3]='4.jpg';
    P=0;
    function ShiftLeft(){
    P--;
    if (P=-1){P+=Picture.length}
    document.picture.src=Picture[P];
    }
    function ShiftRight(){
    P++;
    if (P>Picture.length){P-=Picture.length}
    document.picture.src=Picture[P];
    }
    The picture must then be named and initialised
    Code:
    <Img ID="picture" Src="1.jpg">
    and then use
    Code:
    onClick="ShiftLeft()"
    on your left button and
    Code:
    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:
    e.g:
    Code:
    Picture[4]='myDog.jpg'

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow... thanks!
    you are definitely smarter and cooler than me.

    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.

    http://www.starrtrax.net/iloveCF/andLerura.htm

    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...
    haha...
    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
    Last edited by insidi0us; 09-29-2005 at 02:29 AM.

  • #4
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    904
    Thanks
    0
    Thanked 118 Times in 117 Posts
    solved!
    i made to errors:

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

  • #5
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    laters.

  • #6
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    904
    Thanks
    0
    Thanked 118 Times in 117 Posts
    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.
    Last edited by Lerura; 09-29-2005 at 02:55 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •