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

  • Aaron

    AWESOME! You are the best and cant believe how fast i got a response! AMAZING and you are fixing it!

    Thanks soooo much! πŸ™‚

  • neo

    Hi Sir Ganeshji Marwaha,

    First of all, I love your template. Really AWESOME!!. Thank you so much!

    Anyway, i have a slight problem regarding on styling..

    I noticed that, when i put a border style on the “li” or container, There’s some problem on IE browsers. ie6++ ! the width of the container is shrinking. i don’t know why.. and there’s some excess on the masking effect.

    Can you help me with this..

    Thanks so much!

  • Ganishji, i have pulled the carousel out of the iframe and put it directly onto the page and i am having the same problem! I dont seem to any styles which would be knockng the carousel off center i am stumped!
    Check it out on ff & then on chrome:

    http://www.charmoffensive.me.uk/pages/jewellery/jewellery_lists/angel/s-p-e-c.html

  • Ganeshji Marwaha

    @Alisdair Shepehrd #604: How do you think your carousel implementation is different from the one on this blog, or the demos in the project page. The project page even has a demo named “Image Slider” that is similar to what you are doing. Both the project demo and the blog demo work fine in FF and chrome. So, I am confident there is some CSS quirk that is affecting you. Sorry, can’t be of much help.

  • is this carousel have the option to stop when mouse is on top of the image and the auto option is enabled ???

  • Thanks G, i guess i will have to just rebild the page and isolate the elements till i can get it to work! Keep up the good work πŸ™‚

  • Aaron

    Any update on the fixes you were working on regaurding my earlier comments?

    Thanks!

  • antonio

    Hi Ganeshji,

    I’d like to use jCarouselLite like in your demo called “Custom Widget”, but I couldn’t figure out how the html must be structured in that case, Could you give me some help with the html code structure?

    Thanks,

    Antonio

  • AJ

    Hi
    We are using jcarousellite.js for creating a carousel of images.

    We are facing a major issue here.

    The page structure is as follows:
    1. Parent JSP – which includes all javascript references – jquery, jcarousellite,..
    2. Child JSP 1- Inlcuded in the above Parent JSP has the carousel of images which is populated dynamically.
    3. Child JSP 2 – Included in the above parent JSP has a featured section with featured images again populated dynamically.

    Issue: When the number of feature images are around 5 or more, time taken to load the prev/next red scroll buttons in the carousel is more and noticeable. JQuery will wait for the page load event to complete to display/hide the prev/next red scroll buttons.

    Is there a workaround for this? Can we make the carousel to load and be ready independent of the page load event?

    Thanks in Advance!
    Regards
    Ansu

  • Leo

    JCarousel Lite is a great code.But can you add a new function for it,let the JCarousel can make the pictures scroll or not scroll when mouseover?

  • Mike

    I love this plugin! How can you not like a 2k footprint. I am experiencing one issue, but only in Firefox(pc). I have a two column layout and the carousel is in the left column. The problem is the carousel, when activated, tries to pull my right side content over into the carousel. Kinda looks like its trying to steal it! πŸ™‚ I thought it could be a jQuery release issue so I went down to 1.2.6 but still same problem. I’m using a strict doctype… could that be the conflict? I’m going to have to find an alternative for now but I would love to see this resolved.

  • Bart

    Hi,

    I love the jCarouselLite because it is very easy to implement. I only have one problem with it. When I’m trying to open the carousel in a popup no images are shown. I only see the previous/next buttons.
    I treid several ways to create my popup but all fail.
    I think the problem is the position relative or absolute.

    Is there some workaround for this?

    Thanks Bart

  • Patricia

    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!

  • Xander

    Hello,

    I’m trying to use the Lite Carousel. But I have some problems regarding content and images. I have another “ul” in my content. But then the script is “confused” I guess and is displaying everything pretty weird.

    I think I should just specify the “ul” and “li” in the jCarousel js. But when I do that, my content is displayed (almost) correctly but the buttons are not working anymore so nothing is really sliding.

    Any ideas on how to specify the code so that the js is only effective on some ul’s

    Thanks in advance

  • Xander

    In addition to my previous post, is it possible to have multiple carousels on one page?

    Thanks again.

  • igor

    @Xander: yes, just give different names to classes and instantiate it many times

    Does anybody have problems with Opera (speciffically Opera 10 for Linux)? All the demos work but when i create my own carousel using code from “Installation” section everything works in Firefox, but in Opera I don’t see anything.

  • Maarten

    bug:
    When i used the non circuler version sometimes the last items were not scrollable. I looked into your code and saw:

    if(toitemLength-v)return;else curr=to;

    That has to be:

    if(toitemLength-v+1)return;else curr=to;

    On other lines of code you did it correctly, i was testing with a nice number of rows so i didn’t see it untill it went live πŸ™‚

    Thanks,

    Maarten

  • I had a hell of a time trying to get my .js files to compress with YUIcompressor. Turns out, this plugin uses a reserved word sans quotes which chokes compressor. Very minor typo, but causes a headache for anyone trying to run it through YUIcompressor. The details are documented here on stack overflow:

    http://stackoverflow.com/questions/424469/compression-issues-with-jquery-file-in-yui-compressor/424489#424489

    Other than that, GREAT plugin! Thanks for building and sharing it.

  • Hi Ganesh and others,

    I’m having a little problem regarding your excellent jcarousel and thickbox. When using the carousel next and prev buttons the thickbox is not properly initiated if the user clicks too fast. Instead of the thickbox it’s content is shown in a new browser instance (or the same window).. I think I should be using beforeStart here to init the thickbox? Any ideas?

  • Is there any reported problems with Cufon & jCarousel Lite?

    I have these two lines:

    Cufon.replace(‘.cufon-light’, { hover: true, fontFamily: ” });
    Cufon.replace(‘.cufon’, { hover: true, fontFamily: ” });

    and my markup:

    Blah1
    Blah2


    It creates a blank “li” which you can only remove and get the carousel working normally again when the spans are removed.

    Any ideas?

  • Aaron

    Any updates on issues from 596, 597, 598?

    Thanks for the help! πŸ™‚

  • Nils

    Hi, thank you for that great Plugin.

    I could not find it mentioned (and didn’t want to go through all the comments, to be frank), but it does not seem to support nested content? i.e., there can only be one HTML element inside the .
    I was building something like

    bla
    bla bla


    and that did not work. Should it? If not, you could mention it on the issues page – or fix it πŸ™‚

    Anyway, thank you very much!
    Greetings, Nils

  • maarten

    To prevent users clicking next button when actually is at it’s end you can change:

    $(o.btnPrev+”,”+o.btnNext).removeClass(“disabled”);
    $((curr-o.scrollitemLength-v+1&&o.btnNext)||[]).addClass(“disabled”);

    into:

    $(o.btnPrev+”,”+o.btnNext).removeClass(“disabled”).attr(“disabled”,””);
    $((curr-o.scrollitemLength-v+1&&o.btnNext)||[]).addClass(“disabled”).attr(“disabled”,”disabled”);

    For me this was handy so i know the go() event is only triggered when it is possible.

  • First of all, thanks for this great lightweight plugin.

    I can see that I am not the only one looking for an option to prevent scrolling on mouseover.

    I have made some changes to the script adding a pauseOnHover option to the config.

    http://www.dudal.com/jquery/jquery.jcarousellite.pauseOnHover.js

    Example:
    $(‘#selector’).jCarouselLite({
    pauseOnHover: true
    });

    I would love if this (or some similar functionality could be added to the official release).

  • Vladimir

    Thank you Ganeshji Marwaha!!! It’s a very nice control you have.

    I’ve been thinking if it was possible to load/preload elements of the carousel dynamically. For example I have 50 elements but have markup for 6 and show only 3. Every time I click Next button I want to load from the server next 3 elements.

  • Fadi Chalfoun

    Ganeshji,

    Excellent plugin! This was exactly what I needed for my project to introduce a carousel behavior.

    I did run into a problem however when I had li elements with different heights, I am not using it in a standard way to show images of the same size, each li element has its own unique content. The part that didn’t work so well for me was here:

    li.css({width: li.width(), height: li.height()});

    If the last element in the ul has a smaller height then other elements then all the other elements inherit the smaller height. Which cut off some of my carousel pages. I am quite busy with a project so I may not be completely understanding why this is happening or have come up with the best solution but this seemed to make all the lis inherit the maximum height instead of just the last element in the list:

    var maxHeight = 0;
    $(“li”, ul).each(function(){
    if($(this).height() > maxHeight)
    maxHeight = height($(this));
    });

    li.css({width: li.width(), height: maxHeight});

    Cheers!

  • Thanks for your post!
    The most concerned issue i wanna to say is how cute your blog log is!:)

  • Sandra

    I have a problem that the page is loaded (postback) when clicking the next button when the carousel is on the last element. Same for clicking the previous button when carousel is on the first element. Found that the row “if(toitemLength-v) return;” when not circular in function go(to) only makes a return. Should be return false? Return false helped me.

  • Hi,

    Having problems with the circular setting, on absolutely positioned div content within the container carousel div not displaying on loop back to start, until scrolled one more time.

    Checkout: http://kavekreations.com/iphone.html for an example. There are three items, so after scrolling past the end it returns to the first time, where the relatively positioned image is displayed fine, but the absolutely position div with the text does not display until a further scroll to the next item.

    Strange issue, I cannot seem to see where the problem lies in the script, any ideas?

  • On the first load of jCarouselLite 1.0.1 in firefox 3.5 the image doesn’t take up the entire div, until reloading the page. I’m using a purchased WP theme so I can’t be too sure of implementation, however the error console doesn’t catch anything. I haven’t checked any other browsers for this problem.

    if it helps my page is here: http://watermanoshea.com/staging/

  • Hi,
    you should add this lines of code:

    if(!o.circular){
    $(o.btnPrev).addClass(“disabled”).trigger(“classChange”);
    }

    because disabled isnt set on the btnPrev at startup if circular=false but the button is disabled.

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

    Change: Triggers.

    Triggers are the only way to notice the change of the button-status(disabled or not) an handle it in JS.

  • Hi,

    I had a problem when using non circular and a scroll larger than 1 that it was impossible to scroll to the last items.

    These are the changes i made:


    // If non-circular and to points to first or last, we just return.
    if(toitemLength-1) return false;
    else curr = to;

    $( (curr-o.scroll itemLength-1 && o.btnNext)
    ||
    []
    ).addClass(“disabled”);

  • I have a carousel with visible set to 5 and scroll set to 5. If I have a list length of 6 then I never see the 6th item. Changing:

    if(toitemLength-v) return;

    to:

    if(toitemLength) return;

    Seems to solve the problem.

  • StuPak

    Hi, love the plugin.

    Is there a way to tell it to load a list of images from an external file. Im designing a website where they dont want to touch the html file list, however I hoping to give them a external file they can edit and the main html looks at this file to get the list?

    Thanks πŸ™‚

  • KcB

    The carousel works fine in FireFox, but on Internet Explorer, the next and previous buttons do not work. Any ideas?

    Thank You.

  • Hi!

    Is there a way to get (from the js) the total number of items in the carousel and what item you are currently viewing? (I’m only showing one at a time).

    Regards
    Niclas

  • Hi Ganeshji,

    Thanks for responding to #592; I managed to rectify it by setting the sizes in the CSS.

    There’s an IE7 problem that I can’t seem to solve, which I’ll provide a link to. If you browse to:

    http://robinstudios.com/a&s/

    then click ‘collections’, then ‘solitaire’, and finally ‘Round Brilliant’. You’ll see that the content window is populated with a main image, and to the right, a jCarouselLite vertical bar with thumbs and two directional arrows.

    For some reason, when the thumbs are navigated by clicking the bottom arrow, the whole line of thumbs move down uniformally with every click, until there’s a large gap at the top. This only happens in IE7, but not Firefox, where they stay perfectly centered.

    Would you have a suggestion as to what might be happening?

    Thanks in advance,

    Matt

  • Hi Ganeshji,

    Just realised; if you view your own vertical demo in IE7, you’ll experience the same problem.

    Thanks,

    Matt

  • Firefox 3 renders the UL incorrectly, in 2 rows. For some reason the UL’s width is not enough. If I increase it by 2px, the images are rendered in a single line as they should, but then 2px is already visible of the next image which is not good. Any idea, why this display bug in firefox on my site?
    IE does the same, however, Chrome works OK.

  • Anatoly

    Hi! Great casousel script. Is there any way to externally control the carousel? For example, I want to trigger the scrolling on onMouseOver event on some other elements of my page… Is it possible?

  • Hi,

    I used the plugin to create a scrolling vertical news ticker. It works fine on FF 3.5, Chrome, Safari, and even on my iPhone’s Safari. But the ticker doesn’t move on IE 8 or FF 3.0. I was wondering if you know of any issues with usage? I’ve included my test website in my posting.

    Thanks,
    Steve

  • Roman

    Steve (#643), your websites requires username/password.

    I am also interested in a vertical slider. Would somebody please point me to a well working version?

  • Roman

    I’ve found the vertical demo on this website, but, unfortunately, I don’t have IE 7 to test it in. (Someone has complained about a problem in it.)

  • Hello,

    I’m having an issue with this plugin ; maybe it’s my code that cause the problem. I will try to explain the best I can (i don’t speak english very well).

    You can see the problem live on http://www.restopubcity.com, on the front page, there is 5 tag lines moving around in the right colunm. Everything is perfect until we reach the last tagline, which appear on white background on IE and no text at all on Firefox. There is 5 taglines total. The last tagline is the problem.

    I suspect the use of Cufon.

    I would love to hear from you about this issue, I don’t know what to do now….. If you have a suggestion, I’m listening.

    You can also email me if needed.

    Thanks!

  • Max

    hi Ganesh,

    great plugin!

    I had a quick question – I made a “search” feature which live updates as you type. it just searches the DOM (particularly the content in each LI) for the text you entered, and filters the carousel by setting display:none or display:block for items not matched and matched, respectively. this works fine, except the carousel still thinks those items are there and keeps their width(s), resulting in a mostly blank carousel, with a few of the matches spread out here and there.

    I tried recalling the init function, but it seems to have no effect… is there a way to “reinitialize” or remove/reapply the carousel??

    thanks!

  • Hey, I’m using your jcarousellite plugin on one of my projects. Can you help me with the easing plugin? I can’t find any information on instructions of how to use an easing plugin.

    Thanks!

  • It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.

  • Ars

    Vancouver WordPress (#648),
    The easing plugin lives here http://gsgd.co.uk/sandbox/jquery/easing/
    All of it’s options are in the “Exaples” part.

  • Hi,

    The plugin is great, and in vertical scroll it’s working just as expected. But I have some issues when vertial:false.

    Suppose I have a list with 5 items, so there I see the 1st items on the left after to its right there a blank space, and only after that the 4 more items appeareing, and again – they first all disappear and only after then I see the first item again, meaning it’s not streaming as I expect that after the last item, the 1st item will be just aside him.

    What can be done to achieve the effect like in the demo with horizontal mode?

    Thanks,
    M.

  • Hi,

    Sorry to say I don’t get the jCarousel Lite to work – at all.
    I have studied some other implementations and of course the Demo part here. But no. I’ve got to bee the most helpless JS person ever.

    I made a testpage and this is all of the code on the page:

    $(function() {
    $(“.auto .jCarouselLite”).jCarouselLite({
    auto: 800,
    speed: 1000
    });
    });

    The page can be viewed here: http://www.kompetansetjenester.no/jclite.php

    Can anyone help me out??

    Svein