CJ Simple Slideshow 2.1.1

A Simple Cross-Fade Slideshow Plug-In for JQuery

JQuery Plug-In: Simple Slideshow v2.1.1

Ok, I'm not perfect. My first attempt at a jQuery plug-in was a disaster. It worked great in FireFox and Safari, but it failed miserably in Internet Explorer. I should of known to do a little more testing before I released it, but it was late and I had a bunch of real work to do, so I rushed things. But as the old saying goes, if it doesn't kill you, it only makes you stronger.

In doing this re-write, I made some changes that I think fit more in line with what I was trying to do in the first place. Version 2.0 was a little more complicated than what I intended it to be, I blame this on the excitement of writing my very first jQuery plug-in. On this version I decided to follow my original mandate of keeping things simple.

What was so complicated you ask, well for starters I was allowing you to set styles for the text strings used within the block, i.e. Pause and the caption. In this version, I've added a classname to the containers so you can use simple CSS to style them. It just didn't make sense to over complicate the plug-in with this kind of stuff. The other thing I had going on, was some fancy image centering code. As I was debugging for Internet Explorer, I realized how complicated and messy it was. So I greatly simplified it.

Requirements

I have only tested this with JQuery version 1.3.2. Not sure if it works with older versions, If you give it a try, come back and let me know!. Also, I have tested this with FireFox 3, Internet Explorer 6 & 7 and Safari 4.

Implementing

Implementing the plug-in is pretty straight foward, you just need to have a container that contains a group of images, like so:

<div id="MySlideShow">
   <img src="sample1.jpg" width="250" height="150" alt="This is caption 1." /><br />
   <img src="sample2.jpg" width="250" height="150" alt="This is caption 2." />
</div>

You can style the container with standard CSS. The plug-in will create a wrapper arround the images with a class name of "cj_slideshow_wrapper". It will also create a pause block with a class name of "cj_slideshow_pause_wrapper" and lastly it will create a caption wrapper with a class name of "cj_slideshow_caption_wrapper" (If you choose to show captions). These elements can be styled pretty much any way you please. You just have to be careful not to set the positioning, since the plug-in handles this automatically. For further information, you can check out the demo page for an example of how to style these elements.

Ok, now to activate the slideshow, you need to call the plug-in by placing a load wrapper in your header...

$(function() {
   $(document).ready(function() {
      $("#MySlideShow").cjSimpleSlideShow();
   });
});

...or, place on onload in your body tag, like so:

<body onload="$('#MySlideShow').cjSimpleSlideShow();">

But this method is so un-jquery like, don't you think?

Declaring a CSS rule example

It's important to set the width and height of your container block. Weird things might happen in Internet Explorer. You should set the display to "none" if you plan to have a lot of images, this way they don't all show up when the page is loading.

#MySlideShow { display: none; width: 250px; height: 125px; }

User Settings

You have a few options that you can pass to the plug-in. These change basic functionality and are listed below:

Argument Description Default
autoRun Determines if the slideshow starts automatically. If you set this to false, then you will need to start the slideshow by calling $("#MySlideShow").start(); true
centerImg This is still in the beta stage, but it will attempt to center the images within the main container box. false
delay The delay in miliseconds between slide transitions, 3000
dissolve The amount of time in miliseconds that it takes to do the transition between slides. 70
showCaptions Determines wether or not to display the slide captions. If set to true, the plug-in will use the value of the images ALT tag for the slide caption. true

8 responses to "CJ Simple Slideshow 2.1.1"

Dirk
Dirk says:
This is just perfect, nice tutorial. One thing I would realy like to see is this combined with a simple 'lightbox-like' feature.
In other words: I would like to be able to click the images and popup a large version of the image in a div. Any ideas on how to accomplish this ?
Doug
Doug responds:
@Dirk - Well, I would say why re-invent the wheel. Lightbox (or my personal fav, fancyBox) does this pretty well. You could experiment by putting link tags around the images and then use lightbox or fancybox to do their thing. My code may need a little adjustment, but play around with it and see what happens. If you have any problems and you want me to look at something, don't hesitate to ask. Good luck!
Dirk
Dirk responds:
Thanks Doug, playing around is what I did yesterday. I decided to use slimbox, it works just fine with your plugin.
Miska
Miska says:
How to get rid of the "PAUSE" on the upper left corner when having MouseOver on the slideshow?

Otherwise this is just great. Love it!
Better than the other slideshows I've found and they don't even work as fine as yours.
Doug
Doug responds:
@Miska - You know, I thought I had that as an option you could set, but it looks like I didn't put that in this version. I will need a some time to make the changes, but in the meantime you could search and change:

}).html("Paused").addClass("cj_slideshow_pause_wrapper");

to

}).addClass("cj_slideshow_pause_wrapper");

Sorry about that!
vBulletin 4 Styles
Hi and Thanks for this, i am going to use this to showcase my vbulletin 4 styles, i'll give you full credits for your excellent work.

Cheers
Davy Rudolph
I've tried making each image a link but it only recognizes the first images link on each image... Any ideas on fixing that?
Doug
Doug responds:
@Davy Rudolph - I'll take a look. I think one of the other plug-ins had this problem. I might not have updated this one with the fix.
Davy Rudolph
Davy Rudolph responds:
@Doug - Thanks Doug! I'd like to get this one plugged-in to replace my current that is not working properly. Thanks again!
Doug
Doug responds:
@Davy Rudolph - Well, it's not going to be an easy fix. The way the plug-in is set up, it won't allow mouse clicks, because it's using the "mouseover" event to pause the slide show.

Give me a bit to think about it, I think I'm going to have to re-write a significant portion of the plug-in in order to do this.
Doug
Doug responds:
@Davy Rudolph - Check out the new project CJ Simpler Slideshow. This should do what you need.
Davy Rudolph
Davy Rudolph responds:
@Doug - Thanks Doug. I'll give that one a spin.
dnnny
have you posted "simpler" yet?
Doug
Doug responds:
@dnnny - Not sure what you mean. I posted a new simpler one called CJ Simpler Slideshow 1.0?
Arjun
Arjun says:
This could come in useful, thanks!
Doug
Doug says:
For those of you looking to start the script once all the images have loaded, you can change the "start" function in the jquery.cj-simple-slideshow.js file to this:

function start() {
   sys.total = ($(sys.elem).find("img")).length;
   sys.loaded = 0;
   $(sys.elem).find("img").load(function() {
      sys.loaded++;
      if (sys.loaded === sys.total) {
         sys.timer = setTimeout(setSlide, settings.delay);
      }
   });
}

That should do the trick. If not let me know.
Doug
Doug responds:
Just a heads up. It looks like this is failing in IE. I'm working on a update right now... once I've tested it I release an update.
Sparkii
Hi Doug,
Am very much novice with jQuery and find this really help/clear.

I would like to use the plugin for three sets of images sitting side by side. I implemented this, but I want to delay the middle fade so it starts later than two on either side.

I attempted to do this with this code:
$(function() {
$(document).ready(function() {
$("#slideshow1").cjSimpleSlideShow();
$("#slideshow2").cjSimpleSlideShow("delay",8000);
$("#slideshow3").cjSimpleSlideShow();
});
});

but the delay isn't behaving as I expected. Any suggestions?
Doug
Doug responds:
@Sparkii - I'm looking into right now.
Doug
Doug responds:
@Sparkii - Hi Sparkii... instead of initiating the delay this way:

$("#SlideShow2").cjSimpleSlideShow("delay", 8000);

try:

$("#SlideShow2").cjSimpleSlideShow({delay, 8000});

It looks like the script doesn't work unless you pass it an OBJECT of parameters.

Have something to say? Leave a comment!

You don't have to be registered to leave a comment. Unregistered user's comments will be approved before going live.




You are currently posting as an unregistered user.
This means that your comment will be reviewed prior to going live. If you are a registered user, please . New user? No problem, register for an account, it's FREE! Benefits include, posting instantly, screen name protection, collaboration recognition, subscribe to article updates, and so much more!