iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old May 16th, 2009, 01:39 PM   #1
New Member
 

Join Date: Sep 2008
Location: Michigan
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 AnnabelM is on a distinguished road
Javascript Image Slider - help?

Hi there,
Hoping someone can offer a bit of help here.

I have one thumbnail that when clicked changes the main image. As it cycles through the images in the gallery things go fine, it gets to the last image and stops. How do I get it to go back to the first image instead of stopping?


(javascript for functions and main image)

<table border="0" cellpadding="0">

<tr>
<td width="100%"><img src="images/Brilliance1.png" width="344" height="502" name="photoslider" /></td>
</tr>
<tr>
<td width="100%"><form method="POST" name="rotater">
<div align="center"><center><p><script language="JavaScript1.1">
var photos=new Array()
var which=0
/*Change the below variables to reference your own photos. You may have as many photos in the slider as you wish*/
photos[0]="images/Brilliance1.png"
photos[1]="images/Brilliance2.png"
photos[2]="images/Brilliance3.png"
photos[3]="images/Brilliance4.png"
photos[4]="images/Brilliance5.png"

function backward(){
if (which>0){
window.status=''
which--
document.images.photoslider.src=photos[which]
}
}
function forward(){
if (which<photos.length-1){
which++
document.images.photoslider.src=photos[which]
}
else window.status='backward()'
}
</script></p>
</center></div>
</form>
</td>
</tr>
</table>


(and here is the thumbnail button)

<input type="image" src="images/BrillThumb.png" width="88px" height="128px" name="B1" alt="Next Screenshot"
onClick="forward()">
AnnabelM is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 18th, 2009, 04:26 PM   #2
Reputable Member
 

Join Date: Nov 2008
Location: Lexington, KY
Posts: 243
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 Dubbs is on a distinguished road
Re: Javascript Image Slider - help?

You will need an if statement qthat will determine what image number the user is on if the image is the last, then it resets the number back to 1.

You can try replacing:

Code:
function forward(){
if (which<photos.length-1){
which++
document.images.photoslider.src=photos[which]
}
With
Code:
function forward(){

//Getting the number of photos in the array
TotalPhotos = count (photos);

if (which<photos.length-1){

//Rotating back to the first image if the user advances on the last image.
  if (which == TotalPhotos){
    which = 0  
   }else{
    which++
  }
   document.images.photoslider.src=photos[which]
}
Something that you may want to do is put your JavaScript in your code's header, instead of in the body of the code. You can use's JavaScripts onClick event to advance or go back in the slide show.
Dubbs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
A new simple way to make a image slider- Javascript Code o0DarkEvil0o JavaScript 1 May 19th, 2008 10:37 PM
add image src from javascript function ktsirig JavaScript 1 March 14th, 2008 09:38 AM
Navbar Slider Rick Flash and ActionScript 5 September 20th, 2007 07:45 PM
Image Slider Artry Flash and ActionScript 2 July 23rd, 2007 05:39 AM


Search Engine Optimization by vBSEO 3.2.0 RC8