sans-serif   serif

«

SlideShow – A Highly Extendable MooTools Javascript Slideshow

January 1, 2010

This post is a little out-dated. Check out the post about SlideShow 1.0 here, and the SlideShow microsite. This post was before SlideShow 1.0 was released.

It seems with every new brochure-type website I worked on I was coming up a with a new slideshow/gallery widget. I’d download other great ones like BarackSlideshow, Floom etc. but they didn’t always fit the bill with what I or the designer I was working with wanted–don’t get me wrong, those scripts are great.

Finally I made Slideshow, the ultimate slideshow class. It handles all of the basics of a good javascript gallery and nothing else. No skins, no new elements, no navigation, just the slideshow basics. It implements another one of my scripts, Loop, to handle the autoplay.

Download and links

Download it from the Forge, check out the MooDoc, fork it on github.

Features

  • Autoplay
  • Reverse
  • Show next slide
  • Show previous slide
  • Show arbitrary slide
  • Transitions by slide
  • Durations by slide
  • Default transitions
  • Default durations
  • Several events

Sample code

Store the slides in a container with transition information on their class attribute.

#HTML
<div id="slideshow">
    <div class="transition:crossFade duration:1000">1</div>
    <div>2</div> <!-- gets default transition and duration -->
    <div class="transition:blindRightFade duration:400">3</div>
    <div class="transition:fade duration:1000">4</div>
    <div class="transition:pushUp duration:2000">5</div>
    <div class="transition:pushDown duration:500">6</div>
</div>

Construct it like any other class

mySlideShow = new SlideShow('slideshow');

Demo

Transitions

Rather than having built in transitions (or just a single transition) I borrowed some inspiration from FormValidator and added transitions similar to how FormValidator adds input validation rules. This makes it easy to create your own awesome transitions. Here are the packaged transitions:

  • fade
  • crossFade
  • fadeThroughBackground
  • pushLeft, pushRight, pushUp, pushDown
  • blindLeft, blindRight, blindUp, blindDown
  • blindLeftFade, blindRightFade, blindUpFade, blindDownFade

Adding transitions is a snap. The Class itself has an add function that takes two arguments: the name of the transition, and the function to control it.

So here are a few examples:

SlideShow.add('fade', function(previous, next, duration, instance){
    previous.set('tween',{duration: duration}).fade('out');
    return this;
});

Pretty simple. Since the next slide is directly behind the previous, we can just fade out the previous slide and there’s our new one.

SlideShow.add('blindLeft', function(previous, next, duration, instance){
  var distance = instance.element.getStyle('width').toInt();
  next.setStyles({
    'left': distance,
    'z-index': 2
  }).set('tween',{duration: duration}).tween('left', 0);
  return this;
});

A bit more complicated. First we have to measure the distance our slide needs to travel, then we set it’s left style to be totally out of the slideshow view and change it’s z-index from 0 to 2 so it’s above the previous slides z-index: 1. Once it’s all setup we just tween left back to 0. Our slide smoothly slides over the the previous slide.

SlideShow.add('blindLeftFade',function(p, n, d, i){
  this.blindLeft(p,n,d,i).fade(p,n,d,i);
});

this references the object containing all of the transitions so you can chain effects.

Extend it!

I built this as a base for any slideshow. A slide show framework as it were. I have extended this and used it as is already for several projects and I’m in love with it. Adding a navigation piece could be as simple as:

  var slideLabels = $$('some-elements-in-the-same-order-as-the-slides');

  slideLabels.each(function(el, index){

    el.addEvent('click',function()
      mySlideShow.show(index);
    });

  });

Of course, it’d make more sense to wrap it up in a class, but you get the point. Look forward to several more posts using slideshow here and the forge (three with awesome WordPress integration.)

Download it from the Forge, check out the MooDoc, fork it on github.

MooTools used in this article

Core

RpFlo

Related Posts:

  • No Related Posts

Comments

  • http://blog.computer-service-mallorca.com Michael Pehl

    awesome stuff :o

  • http://blog.computer-service-mallorca.com/2010/01/07/awesome-slide-show-with-mootools/ Awesome Slide Show with MooTools – MooTools and CSS Resources

    [...] Check it out here. [...]

  • http://www.endless-loving.com Sebastian

    Hi,

    I really like the simplicity of your slideshow. It works like a charm and the HTML markup is quite simple. I like especially the class-Attributes that you use for calling the different slide styles.

    I have downloaded your slideshow and compressed the JS files.

    You mentioned a navigation in the same order of the slide. Is it possible that you show me an example? One thing that is important in my opinon is that the slideshow stops when you click on an element in the navigation and it should stop also on mouseover the slideshow – especially when you want to slide content with links in it.

    Can you provide an enhanced version with navigation and mouseover ’stop’? I would make donation afterwards if you provide an PAYPAL link. Just to show my appreciation. :)

    Best regards from Bali, Sebastian

  • http://www.webplus.me/2010/08/05/7-mootools-plugins-you-should-use-on-every-websiteii/ 7 MooTools Plugins You Should Use on Every Website II | Webplus – web developer resource blog

    [...] SlideShow is the amazing slideshow widget created by MooTools contributor Ryan Florence.  SlideShow is extendable, flexible, and easy to implement.  SlideShow allows for more than just images too — any number of elements can added to SlideShow.  The masterful plugin also contains built-in transition types so most of the animation is done for you! Download Example Article [...]

  • pSouper

    Hey Flo, loving the slideshow but would love to know if it can also be used as a ticker that shows multiple entries rather than just 1? – vertical ticker with three entries – scroll up 3 at a time? I have it working fine showing 1 item scrolling 1 at a time but changing the height of the container just spaces them out further :S any pointers? thnx, pSouper

  • http://twitter.com/davidearge davide

    Hi,
    great job,
    would be nice to integrate picasa and flickr directly in the functions of the slideshow if someone need i found this script http://pilon.nl/mootools/files/picasaViewer.js

    Best regards

blog comments powered by Disqus

Comments RSS