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 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Image browsing script skips first 4, but ok on way back...

    I have a small script that has a forward and back button next to an image. On clicking the forward button, it rotates through the available images in the array. However, I've noticed that when you click the first time the page loads, the script skips ahead to the 3rd image in the array. Then, if you click the back button, it will go back thru #3, #2 and then to #1 just fine, and THEN it will progress correctly from there once you click the forward button again.

    Here is the page: http://biology.wright.edu/newsite/

    Here is the code snippets:

    Javascript:
    Code:
    <!-- Hide from old browsers
    // Copyright © 1999 Doug Popeney
    // Created by Doug Popeney (easyjava@easyjavascipt.com)
    // JavaScript Made Easy!! - http://www.easyjavascript.com
    
    	var i = 1
    	images = new Array
    	images[1] = "images/gallery-frontpage/gallery-frontpage1.gif"
    	images[2] = "images/gallery-frontpage/gallery-frontpage2.gif"
    	images[3] = "images/gallery-frontpage/gallery-frontpage3.gif"
    	images[4] = "images/gallery-frontpage/gallery-frontpage4.gif"
    	images[5] = "images/gallery-frontpage/gallery-frontpage5.gif"
    	images[6] = "images/gallery-frontpage/gallery-frontpage6.gif"
    	images[7] = "images/gallery-frontpage/gallery-frontpage7.gif"
    	images[8] = "images/gallery-frontpage/gallery-frontpage8.gif"
    	
    
    function previmg(){
    	if (i != 1){
    		document.image1.src = images[i-1]
    		i--
    	}
    }
    
    function nextimg(){
    	if (i != 8){
    		document.image1.src = images[i+1]
    		i++
    	}
    }
    
    // -- End Hiding Here -->

    HTML:
    Code:
    <img src="images/gallery-frontpage/gallery-frontpage1.gif" alt="Biology Photo Gallery Preview" name="image1" width="343" height="290" />
    		    <a id="left" href="" onClick="previmg();return false;">previous image</a> 
    		    <a id="right" href="" onClick="nextimg(); return false;">next image</a>
    What have I done wrong? I'm sure it's simple... but... forest for the trees here. Thanks!

  • #2
    New Coder
    Join Date
    Aug 2005
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also, I forgot to mention... Is there any way to have the script jump back to the first image once the user has clicked all the way to the last image? Currently, you hit the last one, click again, and nothing happens. I'd like it to sort of "loop" or never end if possible. If not, no biggie. Thanks....

    Ramsey


  •  

    Posting Permissions

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