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

  • Bobby Microby

    Hello guys. There is an issue with Safari Version 5.0.4 (6533.20.27). When i hit the next or prev button, in order to reach the next content entity safari scrolls trough all other images before showing the proper one. The scroll effect is totally broken.
    REgards, Borislav.

  • Yan

    Great plugin, I’ve been using it a lot!

    I needed to control a carousel with another one, so I used the btnGo option on the first one and listed links class of the second one. The problem is that it only works for the images that were there on page load. If you slide the second carousel (the one that controls the first one), the new slides are generated on the fly so no clicks are bound to these slides. To fix this I modified this btnGo section:
    $(val).click(function() {
    to
    $(val).live(‘click’, function() {

    Maybe it can help someone or you could implement this in a future version.

    Thanks!

  • Hi,
    I’m having the issue with the flickering images while the jcarousell constructs itself. I applied the work around suggested, it stops the flickering but the arrows disappear.
    On the site it suggests this code:
    .carousel{
    position: relative;
    visibility: hidden;
    left: -5000px;
    }

    If I use like that nothing happens because I’m using JCarousellite so I used this code instead:
    .jcarousellite {
    position: relative;
    visibility: hidden;
    left: -5000px;
    }
    What am I doing wrong here? Is there a way to fix the flickering and keep the arrows?

    Thanks a lot.

  • Hi!

    is there a way to make it auto scroll down? instead of up?

    when I sent

    vertical: true,
    auto:6100….

    it only goes up… can I change the direction to down?

    Thank you!
    OnYX

  • johnfb

    Is it possible to have captions either above or below the images. I am using the auto scroll version.

    This is a fantastic slider. Thank you so much.

  • Andy

    Having a few issues with auto scrolling. It seems no matter what speed you set auto: to, it just goes at random speed. I’ve currently got it set to 1 and sometimes three items will fly past, then there will be a delay, then one will scroll, then another delay and two will scroll. Anybody else experienced this?

    My options are: {auto:1,speed:500,visible:5}

    I’m trying to get it so there is no delay in auto scrolling but putting 0 means it doesnt scroll at all, and 0.1 seems to do the same as 1

  • webDan

    In IE7 the div.scroller doesn’t seem to get hidden at all, it shows across the whole page.

  • Hello,

    I have this website http://www.lanarkshirediscounts.com/index.php, where I have installed jCarousel Lite . The problem is sometimes, the images are coming in multiple rows. I am not sure how to fix this.

    Can somebody please help me.

    Thanks And Regards,
    Rupak Banerjee.

  • Rob

    If you specify 3.5 visible items it is impossible to see the last half of the last image.

  • zukrin

    Hello,

    as I’ve tested (v 1.0.1), when the number of elements isn’t multiple of the scroll parameter you cannot show the latest elements. I.e if you set scroll=4 and you have 13 elements you cannot scroll to the 13th (to the 14th if you have 14 elements and so on).

    I’ve changed your code to the following (from row 299):

    } else { // If non-circular and to points to first or last, we just return.
    if(toitemLength-v){
    to = itemLength – v;
    }
    curr = to;
    //if(toitemLength-v) return;
    //else curr = to;
    } // If neither overrides it, the curr will still be “to” and we can proceed.

    Zk

  • Joseph

    Is this a bug or a feature ?

    When using external controls every button just scroll 1 element even if my script says “scroll:2”, the prev and next button works fine but external.

  • Dan

    Just wanted to let you know, there is an issue with this script and the YUI compressor, the details are outlined in this stack overflow answer: http://stackoverflow.com/questions/424469/compression-issues-with-jquery-file-in-yui-compressor

  • Hi there,

    I have just installed your plugin, but there is a big issue with it in firefox. I doesn`t scroll at all until you move a mouse… each time you move mouse it is fine, as soon as you leave the mouse carousel stops as well. It happens only in Firefox. I am using Firefox 4. IE9 is all right and Google Chrome is allright.

    But unfortunately Firefox is one of the most importnat browser, so I have to make it work…

    I have tried so far:
    $(document).ready()
    $(window).load()
    and also
    $(function()

    With all of them it is the same. Firefox doesn`t work, the rest browser is fine. Help me with that please.

  • Hi there,

    I have an issue with Cufon and the carousel. Here’s a live example:

    http://themes.adipurdila.com/corpora/

    When you reach the last element and click next, it takes me back to the first slide, but all the cufon generated content is hidden. The same goes for the first element: if i click previous, then it takes me to slide 4 and hides the cufon content.

    Any ideas?

    Thanks.

  • Angelos

    Is there a way to add a separator image between the images?

    For example I want to add 3 separators between the 4 visible images keeping in mind that when scrolling I want them to move with the neighbor image.

    Or I could play with the width and the visible area…

  • Dominique

    Hi there,

    I am having some trouble with the slider. I am not sure if it’s my CSS or my function in calling the photos. Here is a link to what I am working on.

    http://www.law.berkeley.edu/news/slideshow/trial.htm

    I am pulling pictures from flickr and I can see that It does that. However, the prev and next buttons are not working and it is not auto-scrolling either.

    Thanks for the help!

  • Truong

    Is there anyway to disable the “prev” button if there are no more slide to be viewed? Thanks.

  • Truong

    I mean to say hide the “prev” button or make it gray out (not just disable), like the regular jcarousel plugin. I prefer to hide it completely though.

  • Deepa

    Hi! I need to use fading effect for creating a slide show. They do only slide. How can i make it fade?

  • A bit late but re:
    reply #613. Patricia on September 10th, 2009 at 7:05 pm

    Hi!
    Love the jCarouselLit! Totally amazing – once it loads. I’m experiencing a strange problem that the images won’t load at all until the page it refreshed. not sure what’s causing this problem and have gone through the known issues and tried all the quirks.
    Please help site just gone live and client not very happy.
    Thanks!

    —–

    I had the same problem, pre-loading the images fixes this issue;
    here is the code, i put this in the .js file;
    [code]
    jQuery.preloadImages = function(){
    for(var i = 0; i<arguments.length; i++)
    {
    jQuery("”).attr(“src”, arguments[i]);
    }
    }
    $.preloadImages(“1.jpg”, “2.jpg”, “3.jpg”);[/code]

    hope this helps at least one person save time!

    @Ganesh, Thanks for a great plug 🙂

  • Janne

    Hey, the component seems really nice!

    However, is there a way to define the specific item from which the carousel starts? I mean, by default the carousel items always start from the first item but I have a case where I want the carousel to start from the item the user has selected.

    The start-parameter seems to cut down the list, i.e. the user can’t see the first N items at all if using the start parameter.

    Cheers,
    Janne

  • Sam

    We want to send you an donation?
    Do you have an PayPal-Account?

    Thanks for Info!
    Sam

  • Tom McKearney

    I fixed what I believe is a bug in your script while I was implementing “first/last” buttons.

    I have “btnGo” set to have “n” buttons, where “n” is the number of items I have. When I click the last button, it does nothing, because,
    on line 299 of the 1.0.1 js file, you are just returning from the “go()” method if the “to” value is “> itemLength – v”.

    The current lines look like this:

    } else { // If non-circular and to points to first or last, we just return.
    if(toitemLength-v) return;
    else curr = to;
    } // If neither overrides it, the curr will still be “to” and we can proceed.

    I changed these lines to:

    } else { // If non-circular and to points past first or last, fix the “to”

    if (to itemLength – v) {
    to = itemLength – v;
    }

    curr = to;
    }

    I believe this is proper behavior.

    Tom

  • Tom McKearney

    Oops.. forgot to pattern the code properly:

    OLD:

    } else { // If non-circular and to points to first or last, we just return.
    if(to < 0 || to > itemLength-v) return;
    else curr = to;
    } // If neither overrides it, the curr will still be “to” and we can proceed.

    NEW:

    } else { // If non-circular and to points past first or last, fix the “to”
    if (to < 0) {
    to = 0;
    } else if (to > itemLength – v) {
    to = itemLength – v;
    }

    curr = to;
    }

  • Etienne

    Hi, I would like to know if there is a method to easily remove a jcarousel assigned to an element ?
    Is it also possible to remove/add one or further elements in the list in wich we declare a Jcarousellite instance ?

  • Great plugin! But there is an issue: When the user zooms in (in Chrome, at least) the animation is not complete. It jumps around between starting and stopping. I am using autoscroll and easing if that makes a difference…

  • Hi,

    I made some changes to your script.
    You can see it at:

    http://www.scriptbreaker.com/javascript/script/JCarosellite-with-pagination

    Enjoy and keep up the good work

  • Nick

    Hi everyone,

    I’ve noticed one thing that I don’t believe was mentioned in any of the other 1100+ comments. I’m using 2 instances of jCarousel Lite on a page, but even when just 1 is used, the page doesn’t load correctly at all if javascript is disabled, that is, it doesn’t deprecate properly.

    This can be seen even with the demo examples at the top of the page. Turn off javascript in your browser and reload the page. This is an issue because I’ve noticed that 15% or so of visitors to my site have javascript disabled for whatever reason.

    Is there any way around this? I tried the pre-loading the images as mentioned in post #1124 but still nothing shows up if javascript is disabled and the page layout gets all garbled. Not every jQuery plugin has this problem (they will lose functionality but the page still loads and looks OK). Any coding changes that might solve this issue?

  • John

    Hi, i try the vertical caroussel. I work fine everywhere, but not on safari and chrome. I try to init my caroussel inside $(window).load(function(, but it’s still not working. I see my caroussel but i can’t scroll it ! Anyone can help please ???

  • I have installed jcarousellite plugin one of my website and it is working fine thanks for cooperation.

  • david b

    hey thanks for the great carousel.

    is it a known bug that if you apply the jcarousellite to less than 3 images it’s starts to get buggy.

    i only show one picture at a time (solved with css) and use the autoslide feature.

    if you have only 2 images, it first slides and then it suddenly replaces the second image with the first one – without a slide

    and if you apply it to only one image, the image disappears.

    i can disable the script when there is only one image, but the two-image-behaviour bugs me.

    does anybody know a fix to this?
    cheers
    david

  • Is there any (easy) option to randomize the on a auto-scroll ?
    Sample code: $(function(){$(“.filmstrip”).jCarouselLite({auto:1500,visible:6});});

  • Manu

    Hi, Thanks for sharing this script – I’m a total begionner and was able to pick it up and implement it in 15 minutes. Easy, pretty, does the job…
    The only caveat I have is in IE7 & 8 (I don’t bother with IE6) where the width of the carousel is smaller by 30 px which then messes up the elements I have inside. I tried to see if it was something to do with IE’s bug handling margins for floating images but with no joy. It works wonders in all other browsers though.

    If you could shine any light on this, I’d be most grateful – the site is http://www.marinatsartsara.co.uk – The Jacrousellite instance is a verticalnewsticker showing one div at a time (at the bottom of the homepage) – Thanks in advance for your help.
    Manu

  • Derin

    Hi Ganesh,

    I recently came across your site. The jCarousel control is an excellent one and I’m using it in my project. However, I have a specific requirement. I use the “auto” property to automatically display the items. But whenever I do a mouseover on an item, I require to “pause” the slideshow and then once again resume when I mouseout.

    Can you let me know how this can be implemented.

    Thanks in advance.

    Derin

  • bocah

    I’ve a problem if the item less than the visible value. Any suggestions will be plesed 🙂 thank you 🙂

  • briliant. thanks.
    I difficulties using this plugin for a right to left design. is there any update,i wait for its update

  • Hello! I would just like to give a massive thumbs up for this excellent piece you’ve got here. I will be returning for more before long. Cheers.

  • One small suggestion, on line 247:
    when some list items have bigger heights than others, ie, if a li contains a group of elements, this will fix the bug on circular:true since it calculates the height based on the first LI item (which might not be as tall as the first li item.

    li.css({width: li.width(), height: o.circular ? li.eq(1).height() : li.height()});

    if it’s circular, take the height from the first (real) item since this should always be the tallest.

    thanks for this plugin, saved my skin!

  • TK

    I think this is a great and simple plugin for jquery, but I cant seem to get it to work. I must be missing a step or some piece of the puzzle. Please show me what I’m missing here.

    http://tk.hostfury.net/tempSite/

  • James Chapin

    This is brilliant. However, I found one issue with it. I have 15 items in the carousel, with 5 visible. The configuration is as follows:

    $(function() {
    $(“.slider”).jCarouselLite({
    btnNext: “.next”,
    btnPrev: “.prev”,
    visible: 5,
    scroll: 4,
    speed: 800
    });
    });

    I’m not sure if it’s because of the 5/4 visible/scroll settings, but when I get to the end of the carousel, it jumps and skips some images instead of smoothly transitioning to the next 5. I can’t provide a link at the moment.

  • duckpond

    Hello all,
    I played with the visible setting, that can make the next image show half, is there’s also a setting that display half of the prev image? As seen on http://one.org
    Thanks,

  • Dan

    Hi, great plugin and works great for me on all browsers except IE9 where the carousel images are offset and spaced apart. I have tried to find a solution, but having searched can’t find one.

    http://www.coldharbourmarine.com/

    Thanks,

  • Dan

    Hi, looks like my offset issue has been resolved by updating jquery to 1.6.1. Thanks.

  • Maia

    Hi,

    I love your plugin, but am having some difficulty getting the external controls to show up. Can you provide some advice on how to get the external buttons to show up for a dynamic carousel? (I won’t know how many items there will be in the carousel ahead of time).

    Thanks

  • James Chapin

    Hey Ganesh,

    I’m trying to put your plugin (which is AWESOME) into a SharePoint site as a Content Editor Web Part. It works really well in Google Chrome, but not so well in Internet Explorer. It seems that something is wrong with the images, but I’m not sure. I specified that 4 show up and to start at 0, but there are a sliver of one and 5 more that show up. It works as it should, it just looks like all of the images have been condensed in the frame. The arrows are positioned correctly, and I’ve tried messing with the sizes, but I think something may be wrong with the padding.

    Is there a way that I can send you some screenshots so that you can see what I am talking about?

  • Hi,
    Thank you for your great plugin.
    I found a issue when I used it in my .net project. My items dynamical generate by search options. when I set circular to false, the items stand still and didn’t respond to next action.
    I fixed it in function go(to) if not circular. there was an if (to itemLength – v) return; I removed the “- v” and it works great.
    It has another issue in circular. it jumps some last items to the first when I set the visible and scroll in configuration. I didn’t find time to debug it as I need it in none circular config and a lot of work to do. I will inform you asap.

    Cheers.

  • James Chapin

    Nevermind. I figured it out. It was the padding attribute in this line of code:

    .slider ul li {
    width:155px;
    height:175px;
    }

    I took the padding out, and it worked fine.

  • mhenry1384

    Thanks, came in handy for a project I was working on.

  • Hello, three issues that should be addressed or listed in known issues..

    1) when sliding full-window-width slides, the carousel will get messed up on window.resize.

    2) carousel within carousel won’t work, you need to add direct child selector like this (maybe some other places as well)

    ul = $(“>ul”, div), tLi = $(“>li”, ul)

    var li = $(“>li”, ul), itemLength = li.size(), curr = o.start;

    $.each(o.btnGo, function(i, val) {
    $(div).closest(‘li’).find(val).click(function() {

    3) this one is particularly tricky : if you’re using the carousel to slide videos (swfobject flash objects), the CLONING used for o.circular will mess your videos, the last/previous video will get cloned and the clone video won’t load. I tried adding true or even true,true (jquery 1.5) params to the clone, with no effect…

  • Is there a way to get the autoscroll to stop once it has started?