An image slideshow enhanced with random transitional effects

It's time to get real now. Lets create an image slideshow that incorporates IE transitions into the mix. Apart from using just one transition, lets define an array of all IE transitions and have our slideshow randomly pick one from the list to utilize each time the page loads. We start out with such an array:

var global_transitions=[ //array of IE transition strings

Notice the absence of any attributes (ie: duration). We'll just let them fall back to their default values when undefined for simplicity here.

Next, it's time to create the main slideshow function that rotates a series of images by changing a wrapper DIV's .innerHTML property (so text can be shown as well). We check for support for IE filters/transitions, and if found, call apply() and play() just before each slide change. Here is the complete function:

function flashyslideshow(setting){
 this.transduration=setting.transduration/1000 //convert from miliseconds to seconds unit to pass into
 var preloadimages=[] //temp array to preload images
  for (var i=0; i<this.imagearray.length; i++){
  preloadimages[i]=new Image()
 document.write('<div id="'+this.wrapperid+'" class="'+setting.wrapperclass+'">'+this.getSlideHTML(this.currentimg)+'</div>')
 var effectindex=Math.floor(Math.random()*global_transitions.length) //randomly pick a transition to utilize
 var wrapperdiv=document.getElementById(this.wrapperid)
 if (wrapperdiv.filters){ //if the filters[] collection is defined on element (only in IE)[effectindex] //define transition on element
  this.pause+=setting.transduration //add transition time to pause
 this.filtersupport=(wrapperdiv.filters && wrapperdiv.filters.length>0)? true : false //test if element supports transitions and has one defined
 var slideshow=this
 setInterval(function(){slideshow.rotate()}, this.pause)

 var slideHTML=(this.imagearray[index][1])? '<a href="'+this.imagearray[index][1]+'" target="'+this.imagearray[index][1]+'">\n' : '' //hyperlink slide?
 slideHTML+='<img src="'+this.imagearray[index][0]+'" />'
 slideHTML+=(this.imagearray[index][1])? '</a><br />' : '<br />'
 slideHTML+=(this.imagearray[index][3])? this.imagearray[index][3] : '' //text description?
 return slideHTML //return HTML for the slide at the specified index

 var wrapperdiv=document.getElementById(this.wrapperid)
 this.currentimg=(this.currentimg<this.imagearray.length-1)? this.currentimg+1 : 0
 if (this.filtersupport)
 if (this.filtersupport)

For your convenience the script is also presented as an external js file: flashyslideshow.js.

To display an image slideshow, you'd call new flashyslideshow() and pass in a "setting" object containing the various desired settings for the slideshow. Here's an example:

var flashyshow=new flashyslideshow({ //create instance of slideshow
 wrapperid: "myslideshow", //unique ID for this slideshow
 wrapperclass: "flashclass", //desired CSS class for this slideshow
 imagearray: [
  ["summer.jpg", "", "_new", "Such a nice Summer getaway."],
  ["winter.jpg", "", "", "Winter is nice, as long as there's snow right?"],
  ["spring.jpg", "", "", "Flowers spring back to life in Spring."],
  ["autumn.jpg", "", "", "Ah the cool breeze of autumn."]
 pause: 2000, //pause between slides (milliseconds)
 transduration: 1000 //transition duration (milliseconds)


The above slideshow works in all browsers, though in IE browsers that support transitions, a random transition will be applied to it when the page loads. Reload the page to see a different transition being used.

FYI the above demo also uses the following CSS to style it:

<style type="text/css">

width: 200px; /*a width should be defined for transition to work*/
border: 5px solid orange;
padding: 5px;

#myslideshow img{
border-width: 0;