Elastislide – A Responsive jQuery Carousel Plugin

With the responsive awakening in web design it becomes important to not only take care of the visual part of a website but also of the functionality. Elastislide is a responsive jQuery carousel that will adapt its size and its behavior in order to work on any screen size. Inserting the carousels structure into a container with a fluid width will also make the carousel fluid.
Advertisement

View demo Download source

With the responsive awakening in web design it becomes important to not only take care of the visual part of a website but also of the functionality. Elastislide is a responsive jQuery carousel that will adapt its size and its behavior in order to work on any screen size. Inserting the carousel’s structure into a container with a fluid width will also make the carousel fluid.

In a carousel, one could think that simply making its container “shorter” will solve the problem on smaller screens, but in some cases (e.g. when we have bigger images) it might be reasonable to resize the items as well. This and other options are part of Elastislide’s properties.

Elastislide uses the jQuery Touchwipe Plugin which allows you to obtain the wipe event on an iPhone, iPad or iPod Touch.

The images are by Karrie Nodalo and you can find her awesome photos here:
Karrie Nodalo’s Photostream on Flickr
Her images are licensed under the Attribution 2.0 Generic License.

The HTML Structure

The Markup for the carousel consists of a main wrapper that will adjust to the width of any fluid container you put it into. (If you put the carousel in a container with a fixed width, it will not adapt. So make sure that your container has a fluid layout.)
The carousel element will have an unordered list with linked images:

<div id="carousel" class="es-carousel-wrapper">
	<div class="es-carousel">
		<ul>
			<li>
				<a href="#">
					<img src="images/medium/1.jpg" alt="image01" />
				</a>
			</li>
			<li>...</li>
			...
		</ul>
	</div>
</div>

Use your preferred ID and call the plugin like this:

$('#carousel').elastislide({
	imageW 	: 180
});

where imageW is the width of the thumbnails.

Options

Elastislide has the following default options:

speed		: 450,
// animation speed

easing		: '',
// animation easing effect

imageW		: 190,
// the images width

margin		: 3,
// image margin right

border		: 2,
// image border

minItems	: 1,
// the minimum number of items to show.
// when we resize the window, this will
// make sure minItems are always shown
// (unless of course minItems is higher
// than the total number of elements)

current		: 0,
// index of the current item
// when we resize the window,
// the plugin will make sure that
// this item is visible 

onClick		: function() { return false; }
// click item callback
// Example of how to get the index
// of the clicked element:
/*
$('#carousel').elastislide({
    onClick  :  function( $item ) {
        alert( 'The clicked item´s index is ' + $item.index() )
    }
});
*/

It is also possible to dynamically add new items to the carousel. The following is an example on how to achieve that:

var $items	= $('<li><a href="#"><img src="images/large/1.jpg" alt="image01" /></a></li><li><a href="#"><img src="images/large/2.jpg" alt="image01" /></a></li>');
$('#carousel').append($items).elastislide( 'add', $items );

I hope you like this plugin and find it useful!

View demo Download source

Previous:
Next:

Tagged with:

Written by

Mary Lou (Manoela Ilic) is a freelance web designer and developer with a passion for interaction design. She studied Cognitive Science and Computational Logic and has a weakness for the smell of freshly grounded peppercorns.

View all articles by

Website: http://tympanus.net/

Related Articles

Feedback 131 Comments are closed.

  1. 1

    Okay, I got it to work. Now, I’m trying to call an active state on the item I chose (I added captions) but they are not taking. Where should I try to do that with jQuery?

  2. 2

    Great plugin!

    Got it working nicely with a project. Each image is linked to a page, however, but when clicked, they do nothing; as in they dont go to the page they’re linked to.

    Suggestions?

  3. 3

    Hi Mary Lou,
    Really great plugin !

    I just added the removal of nav to the destroy function and a function to remove an element dynamically !

    _removeControls :function(){
    this.$el.find('.es-nav').remove();
    }


    _destroy : function( callback ) {
    this._removeControls();
    this.$el.unbind('.elastislide').removeData('elastislide');
    $(window).unbind('.elastislide');
    if ( callback ) callback.call();
    }


    remove : function( $elem, callback ) {

    // adds new items to the carousel
    $.each(this.$items, function(i, v) {
    if (v == $elem)
    v.remove();
    });
    this.itemsCount = this.$items.length;
    this._setDim();
    this._setCurrentValues();
    this.$slider.css({
    width : this.sliderW
    });
    this._slideToCurrent();
    if ( callback ) callback.call();

    }

    Cheers !

  4. 4

    Hey great tutorial! Is there any way to make text appear on a gray transparency when the mouse is hovering over one of the images? Thanks

  5. 5

    Awesome Tutorial Mary Lou.

    i am working on a wordpress project but i cant seem to get this Carousel to work within wordpress.

  6. 6

    Thanks a lot for the plugin, very useful.. _BUT_:
    when I want to add a new item dinamically to the carousel, it doesn’t work properly…just following the instructions:
    var $items = $('');
    $('#carousel').append($items).elastislide( 'add', $items );

    it adds the 2 with the images outside the and beneath the slider. Indeed isn’t the right behavior.

    Some suggestion?

    • 7

      it adds the 2 with the images outside the and beneath the slider. Indeed isn’t the right behavior.

      Some suggestion?

  7. 8

    I mean:
    it adds the 2 “LI” with the images outside the “UL” and beneath the slider.

  8. 9

    This is a really nice idea, but not very useful without a “circular” option to allow the list elements to loop infinitely. Otherwise it’s a bit of a misnomer to call it a “carousel”.

  9. 10

    I agree with Ben above. Only after implementing this plugin did I realize there’s no circular option, which I need. Everything else is nice enough though.

  10. 11

    just curious if there’s an easy way to create deep-linking or permalinks so that i can send a link directly to an img in the album? thanks!

  11. 12

    The plug in is looking really great !!! But simply doesn’t work: when i click on an image inside the carousel it doesn’t link to the page i want to go …. nothing happen !! Am i doing a mistake ??? Anyone could explain why ???
    Thanks a lot

    • 13

      This question has been answered a few times already in the previous posts:
      In jquery.elastislide.js line 265, replace:
      // item click event
      this.jQueryitems.bind(‘click.elastislide’, function( event ) {
      instance.options.onClick( jQuery(this) );
      return false;
      });
      with
      // item click event
      this.jQueryitems.bind(‘click.elastislide’, function( event ) {
      instance.options.onClick( jQuery(this) );
      //return false;
      });

  12. 14

    Nice plugin! I would like to see captions handled somehow. Overall really nice job!

  13. 15

    When i resize the browser window (command -) the carousel wrapper become double height and leave a blank space under the pictures. Any idea why this behaviour ??? How could that be fixed? I use safari and chrome. Thanks a lot!!

  14. 16

    This plugin is great! I did have to add the jQuery(window).triggerHandler('resize.elastislide'); in order to get the stacking to stop, but for some reason this isn’t working on an ipad with os 4. Does anyone have any idea how to fix that?

  15. 17

    @shadowbreaker and others

    Deeplinking support:

    add ‘class=”selected” to the li IE:



    add this code at the top of the ‘init()’ method :
    var $deeplink = $(‘ul > li.selected’);

    if ($deeplink.length) {
    var deeplinkIndex = $items.index($deeplink);

    if (deeplinkIndex) {
    current = deeplinkIndex;
    }
    }

    Cheerio

Comments are closed.