Image slider for displaying pictures or portfolios

20

I love image slideshows and portfolios with an extra bit of interaction and effects. The problem I found when I wanted to make one of my own was that I always ran out of ideas how to display portfolio items / pictures in a special way. But then it hit me, and the idea for this image slider was born.

imageslider

Download
Image Slider zip-archive
Example
See the image slider in action

Example of the image slider is located at: http://www.gayadesign.com/scripts/slider/

The slider and all its files can be downloaded here: http://www.gayadesign.com/scripts/slider/gdslider.zip

First I want to explain what this image slider does:
This image slider creates a slideshow of images and makes it look like the images have been cropped to only thin strokes. Once the user clicks on an image it will expand across the slideshow and show the picture in its full galore. Click of the left or the right side of the container to navigate to other pictures, the images will keep appearing as if there is an infinite loop of images. It also preloads the images that will be shown on the page.

The pictures in the example are all pictures from http://www.sxc.hu/ a nice site with free stock photos.

Please note that this script does not work in IE6.

Implementing this script is fairly easy. The zip-archive contains everything you need except from Scriptaculous and Prototype. So let’s download that first.

Next, unzip the archive somewhere and upload the contents of the /src/ and /lib/ folders to you web server.

Great! Now that you have Scriptaculous uploaded, download the image slider and unzip it. Upload the contents to your web server (I used the js folder to put the Scriptaculous files in to keep things separated).

Now it’s time to make things work. Add the following code to your <head> tag. Adjust the following code to your preferences:

<!-- include scriptaculous + prototype -->
<script src="js/scriptaculous/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous/scriptaculous.js" type="text/javascript"></script>

<script src="js/extraTransitions.js" type="text/javascript"></script>
<script src="js/slider.js" type="text/javascript"></script>

You can find the html code to put on your page in the example.html file which is the following:

<div id="items">
	<div id="loading">
		&nbsp;
		<div id="pictureLoadContainer"></div>
	</div>
	<div id="caption" style="display: none">
		<div class="background">&nbsp;</div>
		<div id="captionContent" style="display: none"></div>
	</div>
	<div id="overflow">
		<!-- put images with alt attributes here -->
	</div>
	<div id="SlideLeft" class="nav left">
		<img src="images/arrow_left.png" alt="Click to move left" />
	</div>
	<div id="SlideRight" class="nav right">
		<img src="images/arrow_right.png" alt="Click to move right" />
	</div>
</div>

The images you want to load inside the slider have to be 1000 x 620 by default. I’ll explain how adjust this later in the tutorial.

Put the images you want to load in the <div> called “overlay”, just like a normal image on your webpage.

<img src="uritoimage" alt="caption to go with the image" />
<img src="uritoimage" alt="caption to go with the image" />
<img src="uritoimage" alt="caption to go with the image" />
...

You are basically done with adjusting the script if you like the default looks.

To adjust the height and width of several elements take a look in the style.css file.

  • Define the height and width of the item container in: #container #items.
  • Define the size of the navigation buttons in: #container #items .nav.
  • Define the size of the items in: #container .item.
  • If you adjust the height also adjust it here: #container #items #overflow.

If you adjust the widths of elements you also have to change the slider.js file in the js folder. The code is at the top of the script:

/* edit these options according to your CSS */
itemWidth: 250,		//width of an item
totalWidth: 1000,	//total width of the container
navWidth: 112,		//width of the nav including padding
/* end edit options */

Adjust the number to the amount of pixels you had it changed into. Easy not?

The script will load automatically and will only start once all the images have been loaded.

Have fun!

Articles like this one

If you liked this article you can add this post to:


 

19 Comments

  1. Louis Gubitosi said: April 7, 2009 at 2:19 pm | Permalink

    I’ll definitely be using this soon. keep up the good work my man.


  2. Gaya said: April 7, 2009 at 2:21 pm | Permalink

    @louis

    Thanks. I hope this tut may in some people.


  3. Drew said: April 8, 2009 at 9:00 am | Permalink

    Great stuff Gaya, I always expect quality from this website :)

    I would love to see some jQuery implementations of some of your javascripts snippets if you ever get the chance. Keep up the great work!


  4. Gaya said: April 8, 2009 at 9:05 am | Permalink

    Hey Drew,

    First of all: thanks for the comment! Second: jQuery is one of my goals! I’ve been looking at other blogs and commenting / giving feedback / asking questions about jQuery. I think I’ve finally got the chance to try it out now. Stay tuned and maybe I’ll be converting some of my things to jQuery.


  5. Drew said: April 8, 2009 at 9:12 am | Permalink

    Sounds great Gaya, really looking forward to see you work some jQuery magic ;)


  6. Farrhad A | The Dollar Diary said: April 8, 2009 at 10:59 am | Permalink

    Dude! This is a kick-ass idea. I was always looking for something like this. I will let you know when I use it.


  7. Gaya said: April 8, 2009 at 11:09 am | Permalink

    @Farrhad
    Sure thing! Thanks for the nice comment. Hope to see your implementation =)


  8. Mr. Oliveras said: April 19, 2009 at 3:24 pm | Permalink

    Amazing script! Where you set up the kind of effect transition?


  9. Gaya said: April 20, 2009 at 8:35 am | Permalink

    Thanks Mr. Oliveras,

    Adding a transition to an effect in scriptaculous isn’t really hard. where you define the duration you can add:

    transition: Effect.Transitions.NameOfTheEffect


  10. Mr. Oliveras said: April 20, 2009 at 3:33 pm | Permalink

    Cool, thanks again!


  11. Freddy Bee said: September 22, 2009 at 11:32 am | Permalink

    Hello Gaya,

    I read that you have switch to jquery and that it took only fifteen minutes to rewrite a script.
    Will you propose a conversion of that fabulous script soon ?

    Thanks


  12. Frankie said: October 19, 2009 at 10:47 am | Permalink

    is it possible, to this effect as a jquery plugin ?

    I don’t want to mix jquery, script …, prototype … on one page.

    Greetings,
    Frankie


  13. Gaya said: October 19, 2009 at 11:07 am | Permalink

    Hi all,
    It’s been a while since I looked at the jQuery version of this script. It didn’t really work out. If I find the time I’ll post an article about the jQ version for sure.


  14. Marty said: January 19, 2010 at 2:50 pm | Permalink

    I cant get it to work.

    Effect is not defined
    extraTransitions.js()extraTra…itions.js (line 15)
    [Break on this error] Effect.Transitions.Elastic = function(pos) {\r\nextraTra…itions.js (line 15)
    Effect is not defined
    anonymous()slider.js (line 72)
    anonymous()slider.js (line 57)
    [Break on this error] new Effect.Fade(loading, {duration: 0…ng.parentNode.removeChild(loading)}});\r\n


  15. Rui said: February 20, 2010 at 3:33 am | Permalink

    This comment is a bit outdated but Im doing the other way arround (started with jquery) and now doing some magento stuff (need to learn learning prototype) and bump into your script. This is just sweet! Tank you Gaya.

    Hope you or someone here can help me out :

    Instead of reading the ALT atribute, Can the captations come from another element inside the that holds the image?

    If yes, can they parse one tag inside the captation?

    How can I achieve this


  16. Rui said: February 20, 2010 at 3:35 am | Permalink

    (sorry last post lost the html)
    This comment is a bit outdated but Im doing the other way arround (started with jquery) and now doing some magento stuff (need to learn learning prototype) and bump into your script. This is just sweet! Tank you Gaya.

    Hope you or someone here can help me out :

    Instead of reading the ALT atribute, Can the captations come from another element inside the li that holds the image?

    If yes, can they parse one a tag inside the captation?

    How can I achieve this


  17. fem said: March 10, 2010 at 1:18 pm | Permalink

    I have download and completed all the things as guided but still can’t see it working did all tihngs and even images paths are also absolutely perfect. I can just see only loader.gif image loading. Am i doing something or still something has to be done to get it working?


  18. Rhepungus said: March 17, 2010 at 10:35 pm | Permalink

    Great stuff. I barely noticed this website, but it is bookmarked. You seem to take a smart/simple approach to what you do. Always the way to go… Thanks!


  19. hermes kelly bag said: July 9, 2010 at 2:50 am | Permalink

    I have download and completed all the things as guided but still can’t see it working did all tihngs and even images paths are also absolutely perfect. I can just see only loader.gif image loading. Am i doing something or still something has to be done to get it working?


Leave a Comment

Your email is never shared. Get your own avatar with gravatar! Required fields are marked *

*

*