Submit your widget

A Responsive Image Carousel

Created 11 years ago   Views 23030   downloads 5366    Author n/a
A Responsive Image Carousel
View DemoDownload
Share |


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 image 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.



<ul id="carousel" class="elastislide-list">
    <li><a href="#"><img src="images/1.jpg" alt="image01" /></a></li>
    <li><a href="#"><img src="images/2.jpg" alt="image02" /></a></li>
    <li><a href="#"><img src="images/3.jpg" alt="image03" /></a></li>
    <!-- ... -->

Use your preferred ID and call the plugin like this:




Elastislide has the following default options:

$.Elastislide.defaults = {
    // orientation 'horizontal' || 'vertical'
    orientation : 'horizontal',
    // sliding speed
    speed : 500,
    // sliding easing
    easing : 'ease-in-out',
    // 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)
    minItems : 3,
    // index of the current item (left most item of the carousel)
    start : 0,
    // click item callback
    onClick : function( el, position, evt ) { return false; },
    onReady : function() { return false; },
    onBeforeSlide : function() { return false; },
    onAfterSlide : function() { return false; }

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

var carousel = $('#carousel').elastislide();
$('#carousel').append("<li><a href="#"><img src="images/10.jpg" alt="image03" /></a></li>");

Note that if you use the Elastislide for a vertical layout, the height of the container will be automatically set according to how many images you choose to be visible.