Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
Photo Slider Tutorial (0 Comments)
Admin: Posted Date: April 4, 2010

It's worth noting that you can easily use the photo slider to query a server script to load the images.First we need to start off with some images. You'll want these images to be thumbnails that also have a larger view available.

Photo Slider Tutorial

Requirements

  • jquery
  • photoslider.js(http://opiefoto.com/articles/assets/slider/photoslider.js)
  • photoslider.css(http://opiefoto.com/articles/assets/slider/photoslider.css)
  • Very basic knowledge of html & javascript

 

Instructions

Step 1 - Pick Your Photos

First we need to start off with some images. You'll want these images to be thumbnails that also have a larger view available. In this tutorial I'm using a thumbnail size of 50x50 and a full view of 600x400. You can have any size for the "full view" but the thumbnails must all be the same size. We'll start with 4 thumbnails.

 

 

It's worth noting that you can easily use the photo slider to query a server script to load the images.

Step 2 - Import Your Images

Now we need to tell our photo slider which images we want to use. Here we can either set them directly using the bucket hash or we can give it an array of image ids.

in the <head> tag

  1. <link rel="stylesheet" type="text/css" media="screen" href="photoslider.css" />  
  2.   
  3. <script type="text/javascript" src="jquery.js"></script>  
  4. <script type="text/javascript" src="photoslider.js"></script>  

in the <body> tag

  1. <div class="photoslider" id="default"></div>  
  2.   
  3. <script type="text/javascript">  
  4. $(document).ready(function(){  
  5.     //change the 'baseURL' to reflect the host and or path to your images  
  6.     FOTO.Slider.baseURL = 'http://example.com/path/';  
  7.   
  8.     //set images by filling our bucket directly  
  9.     FOTO.Slider.bucket = {  
  10.         'default': {  
  11.             0: {'thumb''t_0.jpg''main''0.jpg''caption''Opie'},  
  12.             1: {'thumb''t_1.jpg''main''1.jpg'},  
  13.             2: {'thumb''t_2.jpg''main''2.jpg''caption''Trash the Dress'},  
  14.             3: {'thumb''t_3.jpg''main''3.jpg'}  
  15.         }  
  16.     };  
  17.   
  18.     //or set our images by the bucket importer  
  19.     var ids = new Array(0,1,2,3);  
  20.     FOTO.Slider.importBucketFromIds('default',ids);  
  21. });  
  22. </script>  

 

If your image urls can fit into a pattern you can use the importBucketFromIds which uses the thumbURL and mainURL string to determine how to generate the url. If you're generating the ids it makes importing much easier. If you want captions on your images set the caption in the bucket.


Step 3 - Load the Photo Slider

 

  1. FOTO.Slider.reload('default');  

Optional - Slideshow

If you want to you can add slideshow controls, along with automatically playing on load.

 

  1. //enable the slideshow and build the controls  
  2. FOTO.Slider.enableSlideshow('default');  
  3.   
  4. //automatically play  
  5. FOTO.Slider.play('default');  

Optional - Preload Images

If you want the images to start pre-loading before a user clicks on them, run the preloadImages method.

 

  1. FOTO.Slider.preloadImages('default');  

Finished Look

Now everything is complete, so just load up your page.

Full JavaScript Code Used in Example

 

  1. <script type="text/javascript">  
  2.   
  3.     $(document).ready(function(){  
  4.         var ids = new Array(0,1,2,3);  
  5.         FOTO.Slider.importBucketFromIds('default',ids);  
  6.         FOTO.Slider.reload('default');  
  7.         FOTO.Slider.preloadImages('default');  
  8.         FOTO.Slider.enableSlideshow('default');  
  9.     });  
  10. </script> 


Notes

If you change the thumbnail width, you will need to modify the this.data[key]['thumbWidth'] in the reload function and set the number to the total width (width + border-left + border-right + margin-left + margin-right + padding-left + padding-right).

 

 

 

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: