jCarousel Lite – A jQuery plugin

jcarousellite-img-02

jCarousel Lite is a jQuery plugin that carries you on a carousel ride filled with images and HTML content. Put simply, you can navigate images and/or HTML in a carousel-style widget. It is super light weight, at about 2 KB in size, yet very flexible and customizable to fit most of our needs.

Did I mention that it weighs just 2 KB?

As if that wasn’t enough, the best part is yet to come… You don’t need any special css file or class name to get this to work. Include the js file. Supply the HTML markup. Then, construct the carousel with just a simple function call.

Visit the project page for more information. There you can find a lot of demos and exhaustive documentation. This blog entry is just a teaser for further exploration.

Installing and getting it to work is as trivial as following the 3 steps given below…

Step 1:

Include a reference to the jQuery library and the jCarouselLite plugin. You can download jQuery here and jCarouselLite here. If you like interesting effects, include the Easing plugin as well (Optional). You may also want to use a compatibility easing plugin if you want to use old easing names. If you would like to navigate the carousel using mouse wheel, then include the mouse-wheel plugin as well (Optional).

<script type="text/javascript" src="path/to/jquery.js"></script>
<script type="text/javascript" src="path/to/jquery.jcarousellite.js"></script>

<!-- Optional -->
<script type="text/javascript" src="path/to/easing.js"></script>
<script type="text/javascript" src="path/to/mousewheel.js"></script>

Step 2:

In your HTML file, provide the markup required by the carousel (a div enclosing an ul). You also need the navigation buttons, but these buttons need not be part of the carousel markup itself. An example follows…

<button class="prev">&laquo;</button>
<button class="next">&raquo;</button>

<div class="any-class">
    <ul>
        <li><img src="image/1.jpg" style="width:150px; height:118px;"></li>
        <li><img src="image/2.jpg" style="width:150px; height:118px;"></li>
        <li><img src="image/3.jpg" style="width:150px; height:118px;"></li>
        <li><img src="image/4.jpg" style="width:150px; height:118px;"></li>
        <li><img src="image/5.jpg" style="width:150px; height:118px;"></li>
    </ul>
</div>

Step 3:

Fire a call to the plugin and supply your navigation buttons. You just managed to architect your own carousel.

$(function() {
    $(".any-class").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev"
    });
});

If you have any comments/suggestions/requests, feel free to drop in a comment or reach @ganeshmax in twitter.

 

Update

Based on popular request, jCarouselLite has been updated to support jquery 1.2.x versions. Goto the download page and download version 1.0.1 to enjoy jquery 1.2.x support. Since Firefox 3 has some issues with $(document).ready() function, try using $(window).load() instead if you face any problems. Hopefully a future version of Firefox or jQuery will fix the problem.

Ganeshji Marwaha

I spend my days as the Director of Technology for Mobility practice and help my clients design enterprise and consumer mobile strategies. Mobile Payments, Digital Wallet and Tokenization technologies are my areas of specialization

  • Vicky

    I’m using jCarouselLite with visible:1 with 5 images that auto scroll and have URL links. Everything works fine EXCEPT the links! The last link (URL) is the only one that works! It overrides the previous links! So with five unique images with unique URLs, the images rotate fine but the only URL that is available is the last URL. It overrides all the previous links! Any ideas where this problem might be located? this is my custom code:

  • vicky

    var controls = []
    $(document).ready(function() {
    $(“div.content_padding p:first”).addClass(‘first’);
    $(“div.content_padding p:last”).addClass(‘last’);
    window.jcl = $(“.jBillboard”).jCarouselLite({
    visible: 1,
    speed: 1500,
    auto: 3500,
    circular: true,
    fade: true,
    btnGo: controls,
    beforeStart: function(obj) {
    $(‘#jcarousel-item-‘+obj.attr(‘rel’)).removeClass(‘current’);
    },
    afterEnd: function(obj) {
    $(‘#jcarousel-item-‘+obj.attr(‘rel’)).addClass(‘current’);
    if ( ‘1’ === obj.attr(‘rel’) ) {
    window.jcl.jCarouselLiteOptions.auto = 0;

    }
    }
    });

    });

  • Mark McDonnell

    Hello Ganeshji,

    I’ve been using your plugin and I recently discovered (since upgrading my website to jQuery 1.5.0) that your jCarouselLite plugin no longer works with this latest release from jQuery?

    Do you know of any reason why that would be?

    For the time being I’ve had to revert my version of jQuery back to the previous version 1.4.4 as that seems to work fine with your plugin but it would be good to find out what the issue is with your plugin and how to fix it to work with the latest version of jQuery.

    Thanks for the great plugin, I look forward to hearing from you.

  • Anthony

    Hi,

    I would like to display more than one carousel on the page and every time I click on a button, all carousel change pictures.
    The only work around I found is to copy-paste the function several time and change the css selector each time.
    Is there a better solution for this?

  • Vicky

    Tony – For mouse over stop, take a look at this link:

    http://plugins.jquery.com/node/479

    and

    http://stackoverflow.com/questions/3352107/stop-the-jcarousel-lite-animation-on-mouseover

    I can’t guarantee it will work, but it’s a start.

  • jcarousel lite does not show up on internet explorer and on firefox on windows computer, but does show up on mac using firefox, opera, and safari. Can someone please help me figure out this issue. I have been struggling with this for a week.

  • Is there a way to insert an overlay option on top of the large picture?

  • Johnny

    Can you move the buttons so they are on top of the image box?

  • As this crops up a lot and no one has actually given a clear example code wise, you can use the following code to make the images fade in and out, as opposed to sliding (the below code displays a single image, useful for say a web banner):

    JavaScript code:

    $(“.banner_images_slider”).jCarouselLite({
    visible: 1,
    start: 0,
    auto: 3500,
    speed: 1000,
    btnNext: “”,
    btnPrev: “”,
    circular: true,
    beforeStart: function(a) {
    $(a).parent().fadeTo(1000, 0);
    var bg = $(a).find(‘img’).attr(‘src’);
    $(‘.banner_images_slider’).css({backgroundImage: “url(“+bg+”)”}, 1000);
    },
    afterEnd: function(a) {
    $(a).parent().fadeTo(1000, 1);
    }
    });

    The HTML:


    I got really sick of looking around for this so hope someone finds this useful πŸ™‚

  • Hi, I’ve found two issues.

    1. Setting {visible:5, scroll:5, circular:false}
    if I have a number of items that isn’t evenly divisible by 5 the carousel will not show the last set of items.

    2. Using two carousels this time, one to serve as nav elements (‘btnGo’ variable using css classnames) for the other carousel (circular is ‘true’) – only the pre-rendered elements for the nav carousel function to navigate the parent carousel. Subsequent elements (before or after) do not appear to have events bound to them.

  • Rog Dammers

    Hi all, anybody please help? ! am an absolute noob. Does any body know how the code would be for the “Non-Image Content” feature and also if I can set the size of the boxes. Any help would be muchly appreaciated

  • taz

    Thanks to the creator of the plugin.

    Effects get out of order in case we hide/show the container of the content to which jCarousel is applied. Like in my case I have a section of website which user can show or hide at her/his preference. And that sections contains the jCarousel. So when s/he does it overall alignment got affected though the animation continuous to work. e.g. I am showing 4 slides at a time and after hide/show it start show half (or a part of) slides from left and right.

    Can anyone help on this.

  • @Rog Dammers

    result() as $item): ?>

    opis, 75); ?>

    Why doesn’t work like this:

    .. why does it have to be does it have to do something with jquery.

  • @Rog Dammers

    I have pasted javascript and html/php code.
    http://codepad.org/XPsCMCnl

    Why do we need div id and not ul id, it should work, or does this have to do something with jquery that operates only with divs.

  • @ Johnny
    yes it can be done with css.

  • chris

    I have an example of the “IE drift” issue that (338) Scott Galambos and maybe a few others are having. Here is a url with the issue:

    http://www.marketscout.com/various_sites/symposium11/

    The vertical scroll is in the center of the site with red borders so you can see the pixel shift clearly. I’ve tried plenty of CSS margin/padding fixes and i tinkered with the visible values in the the javascript. Not getting me a flush line up with the top of each li tag. Any help on this would be grand!

  • Gilles M.

    Thanks for the awesome script! But I have a question:

    I used the vertical scroller, but instead of the content scrolling from bottom to top, I would like to scroll it the other way arround. How can I do that?

  • Dan

    Love the plugin and I have much of it working well. I’m looking for a way to have this updated dynamically, to replace a Flash gallery/promo that is updated daily via XML. I’m playing around with XSLT, which is working with the xml exactly as I’d hope. Only problem is I can’t get the carousel to function/scroll; I just get all the items displayed. Below is my code; I’m wondering if anyone has any solutions or if maybe I need to pursue another method for dynamic updating. Thanks! (Oh — yes, js files are referenced in the header; the xsl file is in the same folder as a working carousel html file that references the same js.)

    $(function() {
    $(“.carousel”).jCarouselLite({
    btnNext: “.next”,
    btnPrev: “.prev”,
    auto: 12000,
    speed: 400,
    vertical: false,
    circular: true,
    visible: 1,
    easing: “easeinout”,
    });
    });



    <<
    >>

  • Dan

    Hmm, here’s the rest of that code:



    <<
    >>

  • Hi, loving the widget! I have it working for a scrolling Twitter feed at http://www.roundedpr.com. Just one question: is there a way of making the LI elements variable height instead of the same height? Because it’s truncating some of the Tweet text. Thanks!

  • Hi, congratulations for your work!
    Is there a way to disable a carousel?

    Say I have a page with a carouselled , and I need to uncarousel it from time to time. Any idea on how to implement a .disable() function please?

    Thanks!!
    germain

  • samir

    please let me know why the carousel dosen’t work what codes am i mississing thanks

    <<
    >>

    $(function() {
    $(“.anyClass”).jCarouselLite({
    btnNext: “.next”,
    btnPrev: “.prev”
    });
    });

  • Richard Bland

    For those of you who would like to use AUTOSCROLL and have it PAUSE ON HOVER, I can confirm that the following patch works…

    http://plugins.jquery.com/files/issues/jcarousellite_1.0.1.hoverPause.txt

    Copy and paste that patch into the existing jCarouselLite.js file and save it.

    To initialise the pause on hover effect you have to include the following line in the function script that you add to your web page: hoverPause: true

    My example script – (Copy and paste to read it better)

    $(function() {
    $(“.rotate”).jCarouselLite({
    btnNext: “.next”,
    btnPrev: “.prev”,
    auto: 10000,
    speed: 1000,
    visible: 4,
    easing: “bounceout”,
    hoverPause: true
    });
    });

    So recap: Follow the above link, copy and paste the text, paste the text in the existing jCarouselLite.js file and save it. Then you can add my example script above to initialise the AUTOSCROLL and PAUSE ON HOVER.

    Note: You can get rid of the OPTIONAL variables, they are just what I use, but keep the REQUIRED ones.

    Hope that helps!

    BlandyDoes

  • Rene

    Hello,

    i use the jCarouselLite :-), but i have a little Problem.
    I need differend width for the Li Container. What Can i Do ?

    Best Regards from Germany
    RenΓ©

  • kim

    Hello! Is anyone able to help with the custom widget application? I have the scroller implemented and working. As of now, it’s scrolling vertically. Trying to get it so when thumbnail is clicked, a larger image appears to the right in the gray box. Any ideas? Thanks ahead of time.

    http://www.anthologywebdesign.com/bp/test/renderings.php

  • Nicolas

    I noticed something strange, when I only have 1 image in the galery,the image is not displayed. If a I add a second image both will be dislayed, if i remove one of the , then again, the image won’t be displayed…Any idea? or solution ?

  • cool thanks i will use this in my portfolio website.

  • Hi, I am very new to this so please be patient with me, but I have two questions

    1. The first picture slides to the left when I click the button, but I want it to be invisible then (so that the carousel always has only 3 visible items at a time). How do I do that?

    2. This is related. How do I get the buttons to surround the carousel rather than having them above it as it is right now?

    Thanks.

  • NickC

    Just have implemented the jCarousellite and have set continuous = true, scroll = 0, visible = 1. The desired effect is to show one image and move forward or backward by one. This is not occuring.

    It loses track of its position of simply animates the ul in such a way that nothing is visible. Has anyone been able to correct this?

    Thanks.

  • sam

    Cool! Is there a possibility for donation? Paypal?
    You did a great job!

  • Marc

    Hi,

    awesome plugin, thanks!

    I have one little issue though. Maybe you can give me a tip how to handle this:
    While the slider works fine in Firefox (3.6.15 OSX version) the script calculates the hight for the LIs incorrectly in Chrome (10 – OSX) and Safari (5.0.3 – OSX) killing my page layout. (LIs should be 50px high – chrome and safari show 39px).
    Here how it should look:
    http://rosenthalusa-survey.com/asi/asseenin.html
    and here how it looks incorrectly (chrome and safari)
    http://rosenthalusa-survey.com/asi/asseenin2.html

    Thanks for looking into that.

    (I could not find a search function for the comments – so please excuse me for asking again in case this problem has been addressed before)

  • Marc

    Hi,

    me again.

    I figured it out:
    I did not assign a height value for the LI elements in my css.

    Since the plugin extracts the LI measures (var liSize = o.vertical ? height(li) : width(li);) it could not find any value for the height there.

    Looks like Firefox’ rendering is a bit smarter and figured it out..

    Anyways, problem solved!

    Thanks anyways!

  • Sam

    Thank you so much for your great plug in. It has proved very easy to use and very useful. I have encountered a strange behavior that I can hope you can help me resolve. I cannot post the website address yet, because I don’t know if it conflicts with my client confidentiality. But here is the basic setup for my script:

    $(“.caseStudies .carousel2”).jCarouselLite({
    btnNext: “.caseStudies .next”,
    btnPrev: “.caseStudies .prev”,
    circular:false,
    speed:600,
    scroll:1,
    visible: 1,
    afterEnd: srcSwitch
    });

    Nothing too crazy, with a call back function at the end. Each in my carousel contains at set of 5 div’s, each with an image and a caption that links to a page:

    Business Expansion Application Brief

    Business Expansion Application Brief

    Business Expansion Application Brief

    Business Expansion Application Brief

    Business Expansion Application Brief

    That is the basic set up of each slide in my carousel. The callback function is doing a simple bit of js that prevents the images for slides that are not visible from loading until that slide comes into view. Now about the strange scrolling behavior…

    Everything was fine in testing. I was using several of these carousels on a page. They worked perfectly. But in the final website, some of the carousels required a LOT of slides to show all the elements. That didn’t seem like a problem until I noticed today that after many many clicks (with the left: property greater than -10000) the carousel speed shoots up and it scrolls looks twice as fast (maybe faster!) as I specified.

    Any ideas what might be happening? Your help would be most appreciated!

    Sincerely,

    Sam

  • >>Thanks for a cool script but it looks like setting the β€œstart” value to something other than 0 breaks external controls?

    if you set start variable dynamically, try to do this:

    start = parseInt(start);

  • Michele ODell

    I have a non-circular carousel with custom images for the next and previous buttons. How do I modify the disable code below to swap out the image instead of adding a class? A class doesn’t work with a custom image.

    // Disable buttons when the carousel reaches the last/first, and enable when not
    if(!o.circular) {
    $(o.btnPrev + “,” + o.btnNext).removeClass(“disabled”);
    $( (curr-o.scroll itemLength-v && o.btnNext)
    ||
    []
    ).addClass(“disabled”);
    }

  • Marcelo

    Hi, I’m having this error
    “el[0] is undefined”
    I’m using jquery-1.4.2.js

    Any help will be appreciated

    Thanks

  • Hi

    I have used your script a couple of times earlier, with great success.

    But now i have some issue with the first img/panel being repeated twice.

    I’m setting up this site in a test subdomain http://new[dot]pulsure.dk – it will soon be closed again.

    Thank you for a great script.

    Brian
    amaster.dk

  • ruijian

    I use it in IE7 ?if is in table ?it cannot work?I need help?

  • Rene

    Could anyone show some code to make the start number random? I really cannot program in js and I’ve been googling for hours without result πŸ™

    thanks in advance

  • Could anyone show some code to make the start number random? I really cannot program in js and I’ve been googling for hours without result πŸ™

    thanks in advance

  • Awesome plugin man, just one small question:

    Sorry if this question has been asked before, but I was unable to find the exact answer I was looking for.

    I need to make a vertical text ticker that moves smoothly, with no discernable pauses, and repeats indefinitely.

    I found JCarouselLite, and got everything looking how I want.

    However, if I set the “auto” interval to 1, or even 0.01, there is still a pause inbetween each movement. I’ve also set the easing to “linear” to remove that from the equation.

    Next, I tried setting the scroll to more items total, and a longer duration, to minimize the pauses. With the duration set to 18000ms and 51 items, it looks great. One problem, it delays for 18000ms before getting started the first time, and every subsequent time.

    Page here: https://secure.awarenesslife.com/tickertest.cfm

  • Ali

    Hi Ganesh,

    The information which you have given above is Superb!!!.

    Iam new to JQuery and JCarousel…….

    I have created a web user control and downloaed two .js(jcarousellite_1.0.1.pack.js and jquery-1.2.6.min.js) and uploaded a four images in a new folder. did everything as suggested. Please see the below code

    $(“.default .jCarouselLite”).jCarouselLite({
    btnNext: “.default .next”,
    btnPrev: “.default .prev”
    });

    <<
    >>

    My question is where do i need to place step 4 code so that it starts working.
    $(function() {
    $(“.anyClass”).jCarouselLite({
    btnNext: “.next”,
    btnPrev: “.prev”
    });
    });

    because i have to implement JCarousel in sharepoint 2007 can you please help me on this. i will be very thankful to you…
    waiting for your Kind response..

    if you need any kind of information please let me know..

  • Thanks so much for this great carousel! I’m actually using it on my website. I would like to put multiple carousels on one page. How could this be accomplished?

    Right now, with 2 carousels, the controls (next, previous) for both carousels control just the top carousel. πŸ™

    Thanks for any help you can provide!

  • novellino

    Hello,

    I know that through the afterEnd callback function I get the object that is active after the animation. Is there a way to get just the number of this object? For example if the object is the second image, to get only the number 2?

    Thanks

  • Hi Ganeshji, great script. I wanted to let you know that I found a bug with the implementation of jCarousel Lite v1.0.1 and how it uses selectors to get the number of li’s in a carousel. In my implementation I’m using list items within each carousel item. After looking at your code the following would result in jCarousel thinking that it has 3 items in the carousel when really there is only 1.

    The use of $(‘li’, ul) will return all nested li’s regardless of how deeply nested they are in the dom structure. To handle this issue I’ve modified a few lines of code in your constructor to fix this issue. Feel free to apply these changes if you see fit.

    var div = $(this), ul = div.children(‘ul’), tLi = ul.children(‘li’), tl = tLi.size(), v = o.visible;

    if(o.circular) {
    ul.prepend(tLi.slice(tl-v-1+1).clone())
    .append(tLi.slice(0,v).clone());
    o.start += v;
    }

    var li = ul.children(‘li’), itemLength = li.size(), curr = o.start;

  • Sorry my first comment didn’t show my example code. I posted up the solution on my blog if you want to check it out in more detail: http://blog.psyrendust.com/2011/03/30/too-many-carousel-items-in-jcarousel-lite-v1-0-1/

  • Hi Ganesh,

    I really like the plugin and have a suggestion for when the plugin loads and the carousel is initially hidden. You have this listed as a know issue, but I think I have a solution for you. If you modify your height and width functions as below, it should work for you if the user has set the width and height of the li items in css. This can be done either inline or in a css file. Here is the code change:

    function width(el) {
    var w = el[0].offsetWidth + css(el, ‘marginLeft’) + css(el, ‘marginRight’);
    if (w == 0) {
    w = el.css(“width”).replace(“px”, “”);
    }
    return w;
    };

    function height(el) {
    var h = el[0].offsetHeight + css(el, ‘marginTop’) + css(el, ‘marginBottom’);
    if (h == 0) {
    h = el.css(“height”).replace(“px”, “”);
    }
    return h;
    };

  • I have made another iteration on the width and height functions to include the margins. Not sure if u need to do this for padding as well. here is my update:

    function width(el) {
    var w;

    if (el[0].offsetWidth > 0) {
    w = el[0].offsetWidth;
    }
    else {
    w = css(el, “width”);
    }

    return w + css(el, ‘marginLeft’) + css(el, ‘marginRight’);
    };
    function height(el) {
    var h;

    if (el[0].offsetHeight > 0) {
    h = el[0].offsetHeight + css(el, ‘marginTop’) + css(el, ‘marginBottom’);
    } else {
    h = css(el, “height”);
    }

    return h + css(el, ‘marginTop’) + css(el, ‘marginBottom’);;
    };

  • Dave

    Adam
    I think this is exactly what I’ve been after, it seems to sort out my multiple width issue I’ve been having, but it stops the carousel from working and reverts it back to a list – any ideas what I’m missing?

  • Sebastjan

    best carusel on the web! πŸ˜€ Sebastjan