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

  • brett

    Hi,

    I love the lava lamp plugin…looks great! I’m having a problem with it though. The navigation links within the plugin are not working. Nothing happens when I click on the links. How do I fix this? When I disable javascript the links function properly, so its obviously something with the javascript. Any ideas??? Thanks a lot!!!

    -Brett

  • regarding: points 70 and 71.. (copied below)

    First I tried to fix this by moving the whole lot left with CSS, this was good, but then you can visibly see the carousel loading the first image when it reaches the end.

    I got around this problem by adding a margin right !important to the ul. This moves the whole shebang accross to the right and hides the image load, but then the last item displays first…

    Next move, in php (or your language of choice) control the array so that when it outputs the elements, the one you want to appear first must be the last in the array..

    hope this helps!

    #
    70. Luc on January 24th, 2008 at 12:18 pm

    BUG:
    Hi, I think I’ve found a bug with jclite, when using fractional display – I’m showing 1.5 items, and when i get to the end of the list, where there should be 1/2 of the first item shown, i get nothing, and scrolling to the “next” item then goes out of sync and starts in the middle of the first item. Is that why you’ve set circular:false in the fractional example?

    $(”.portfolio-carousel”).jCarouselLite({
    btnNext: “.portfolio-carousel .next”,
    btnPrev: “.portfolio-carousel .prev”,
    visible: 1.5,
    scroll: 1,
    start: 0.5,
    speed: 400
    });

    Any ideas on how to fix it?
    #
    71. Luc on January 24th, 2008 at 12:59 pm

    BUG:
    Also, when you specify visible in .5 increments, the carousel doesn’t seem to start in the right place – it starts with 1/2 of the last item first, then the full first item. Only when you go up to visible:2, does it behave normally. When you add circular:false it works OK…

  • I am having trouble with making it work in Safari; navigation works, but the images do not display – Firefox and others are fine. Any ideas?

  • Hi Ganesh,

    I, too am having a problem in Safari (3.2.1). Sometimes the images load perfectly and other times the height varies from either 30px or 85px. I have set the height of each li to 350px, but something seems to be overriding it. It is an intermittent problem – but often times it happens the first time you load page. When I have taken out the class “nonImageContent” the images display their actual size – however the js doesn’t work – it becomes a long list. Any help you can give me would be greatly appreciated – I have spent way too much time trying to figure this out.
    Thanks.

  • Michelle

    does your lite version support multiple carousels? i’ve tried it but wasn’t able to get external controls to behave correctly. i hit one external control and it would scroll all the carousels simutaneously.

  • I don’t see it posted above, so I wanted to let everyone know that I posted a modded Jcarousel Lite solution that includes a Pause control that toggles on and off with a “paused” css class.

    http://www.erikhobbie.com/technology/jquery-auto-slideshow-with-pause-feature/

  • Ryan

    It may be worth changing the following from (about line 300):
    if(toitemLength-v) {
    return;
    } else {
    curr = to;
    }

    to:

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

    This will allow you to still scroll to the last one if say you’re scolling 4 items at a time and have 10 in the list. Beforehand you could only get as far as item 8.

  • Jase

    Thanks for the great script! It works nicely. I found an issue that I though you might like to know about.

    ISSUE: for four images, set visible: 4, start: 1.5 (to show that there are images on either side that can be viewed), and when all four images are viewed by scrolling the half images disappear.

    Once again great job, and hopefully you can fix the issue.

    Jase

  • gorkreg

    Thanks for the Carousel. I was looking for something like that for a while.

    I have a problem with the loading of the images. Everything works fine in all browsers but in Explorer (even in IE7) the images don’t load until you hover over them (and then they dissapear again as you scroll). I have another javascript effect applied but I don’t think it’s the cause of the problem because it still happens when I delete the code.

    I really don’t know where to start from. Is it the cache?, the CSS? the javascript? Here is the page to see if you have any ideas. http://www.gorkaregidor.com/web

    Just ask me if you have any questions regarding the code. Thanks again.

  • gorkreg

    I actually think I found where the problem is. It’s the “absolute” position that I needed to give to each image for the other effect to work. How can I make it work in Explorer???

    The funny thing is that yesterday it worked fine in IE 6 and 7 and today… not. I don’t remember changing anything although, rationality says, I probably did. At least I know that it’s possible to do it 🙂 But I don’t know how 🙁

  • gorkreg

    Ok. I finally found what I had changed that made it work. The usual javascript code:

    All sorted now.
    I feel like Groucho Marx. Just having a conversation with myself 😉

  • gorkreg

    This doesn’t work again in IE 6. Am I going crazy?

  • @Gorkreg:It is working in IE6 for me. Although I am running Windows in VMware and IE6 in IEtester, so it’s not a perfect test. One piece of good news, IE8 is supposedly being pushed out to everyone in the next couple of weeks.

  • gorkreg

    That sounds great! Death to Explorer 6 once and for all. It’s weird though because most of the time the images never finish loading in IE 6 (only when I hover over them) and sometimes they do. It has something to do with cache of the page I guess but I am completely lost there.

  • asmith

    I’m using auto: true.

    1. How can I stop it from moving by onmouseover ? and then change back by onmouseout?

    2. How can I make it like “onmouseover” goes left (or up) and “onmouseout” goes right (or down) ? like the prev and next buttons but with onmouse over and out…

  • asmith

    3. How to make ‘btnNext: “.nonImageContent .next”‘ when there’s no button on the page ? (only auto)

  • James

    Is it possible to have the next and back buttons effect more than one carousel? I have two different carousels on a page and I want them both to change at the same time when the button is pressed.

  • Sune Radich

    I am trying to get jCarousel Lite to show me two full li elements, and then only part of the one before and after the two. Im not trying to show half an element, but more like 20% of it.

    Did anyone make anything similar? I’ve tried to mess with the code, but havent been able to make anything that works like I want it.

  • Great Plugin. I am currently using the code below to run after the scroll animation. It works once but then when the next item is auto scrolled in it does not work anymore. Is there anyway to have the AfterEnd keep being applied as the list is scrolled.

    jQuery(“.show .jCarouselLite”).jCarouselLite({
    btnNext: “.show .next”,
    btnPrev: “.show .prev”,
    speed: 900,
    auto: 5000,
    easing: “backout”,
    circular: “false”,
    afterEnd: function(a) {
    jQuery(“.mid img”).attr(“src”, jQuery(“.show img”).attr(“src”));
    }

    });

  • Hi

    Must say great script!! But I am trying to change the width and therefore the number of items shown. I have changed the visible setting but it does not make the box wider… Can you email me an example?

    Thanks very much

    Adam

  • d

    im lovin this plugin. does exactly what i wanted but i just ran into a problem using this plugin with the thickbox plugin.

    im using the carousel to show divs with images and text in each frame. and i have links in the text of each frame that are supposed to open some content in a thickbox.

    seems like links in the carousel dont open in a thickbox like they should. but the same exact link works if its outside the carousel’s ul.

    you can see an example of the issue at http://punkassbitch.com

    any idea on whats going on or how i can fix this?

    thx.

  • d

    update on my issue:

    looks like thickbox will work as long as there are enough frames in the carousel that you have to scroll.

    but thickbox stops working on the same exact link if it loops around to the frame again in the carousel.

    weird.

  • solneman

    hello,
    I would like to implement an image counter that would
    display something like this: 1 of 10, 2 of 10 and so on.
    I know jCarousel Lite has a variable called “curr” but I don’t know
    how to use it.

  • bob

    err the links dont work ? I.e not clickable

  • Peter

    Thank you for the great plug-in!

    I’m using jCarousel Lite to cycle through a list of news items. I have the carousel set up to auto scroll and to run vertically. When the carousel is set up, the height of each li element is set to a static amount and this can cut off some of the news items in the list if they are longer than the height allows.

    I can work with this (by limiting the length of the news items), but was wondering how one might go about altering the plug-in to handle list items of variable length? My current thinking is to change the distance the items slide when animating based on the height of the item that is disappearing. This might leave some items cut off if a short item is disappearing while a longer one is coming in, but that seems (without seeing it in action) to be an acceptable occurrence.

    Any thought you might have on this subject would be appreciated!

  • Craig

    best image slider on the internet.

    However, performance can be improved.

    And there is an issue with sliding big image (500×300), the images flickering.

  • rtc

    Hey I just thought you might want to see where your plugin is being used.

    I actually added a modification that pauses the auto scrolling when you put the mouse over it. Thanks for building this, it came in handy.

    http://getwwa.com

  • CAN THIS SCRIPT BE COMBINED WITH J CARUSEL? I MEN USING J CARUSEL AND HAWE THE MOUSE SCROLLING EFFECT ? jCarousel – sorgalla.com ///
    IS THIS TO BASED ON ONE AND OTHER?
    THNX FOR REPLAY WORKING ON A PROJECT… WOULD HELP OUT… http://WWW.0001.TK

  • Hi, for the next version you might want to rework this to return a jCarouselLite object that has the ‘go’ function exposed so that this can work better with any external controls.

    In the mean time, I extended mine to allow a select input to control the movement.

    Add a selectGo option to the top and add this code:
    if(o.selectGo)
    $(o.selectGo).change(function() {
    moo = parseInt($(this).val())+1;
    return go(moo);
    });

  • nsf

    This is a brilliant plugin. I only have two question
    1) how to implement a pause on hover
    2) how to implement pause resume buttons

    Could you provide some instruction?
    Thank you.

  • Hello
    It’s a great plugin. Keep up the good work
    I want to use it with jqueryUI accordion (theme: south street)
    Then jcarouselLite is not working as expected. I cannot see the images

    Thanks

  • Simon Burnett

    Hi, when using non-circular mode the ‘disabled’ class isn’t added if the initial number of elements is the same or less than the ‘visible’ property. I wanted to blank out the nav buttons if the user couldn’t nav that direction so I had to do 2 things:
    1) Add a ‘button.disabled’ class that hid the button.
    2) Add some code to hide them upon init if required (at line 235):
    if(o.circular) {
    ul.prepend(tLi.slice(tl-v-1+1).clone())
    .append(tLi.slice(0,v).clone());
    o.start += v;
    }
    else{ //******ADDED BY ME*****//
    // Disable ‘prev’ button
    if (o.start == 0)$(o.btnPrev).addClass(“disabled”);

    // If same/less elements, disable ‘next’ button
    if (tLi.length <= v) $(o.btnNext).addClass(“disabled”);
    }

    Hope this helps!
    Simon

  • Bob

    Did anyone comment on the bug report from Brian Harris? I’m referring to comment #110, bug#1.

    To restate: I’m setting up a list of items that is variable length, with circular set to false. The variable-length list is not evenly divisible by my scroll amount. E.g., I have 18 items, I have scroll set to 5, and I have circular set to false. I am not able to scroll to the last 3 items… the remainder is not viewable.

  • I spent a little time and fixed the last issue I just mentioned. Hopefully I can submit code in this comment and it won’t get overwritten. Just replace these two lines:

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

    with the following:

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

  • cardob

    New to jQuery and jCarousel Lite. 1st many thanks for the script. Has been implemented and its working.

    Having problems customizing to specific needs. Specifically using items(images) with different widths.

    Have used (Comment #329-330 by Jorge) and its works. But the images are not evenly spaced. Would like to have then spaced about 5px apart from each other. Any ideas/help? Greatly appreciated!

    Side Note: Have noticed that when my test page first loads the carousel does not show until the page is refreshed. Any thoughts on solution? Many thanks!

  • Hi,

    I have an issue. I have 73 images in my carousel with circular set to false, visible set to 10 and scroll set to 10.

    When it gets to 70 it stops and won’t show the final three.

    @Bob Ralian seems to have some code that I think relates to this, but I can’t find where to put it.

    Any help would be great.

    Oh, love this plugin btw!

  • @Phil
    I saw that jCarousel Lite lives on the jquery plugins site, so I submitted my patch for this issue there.

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

  • @Bob, works a charm! Thanks very much.

  • Eclipse

    Hey!

    thanks for this awesome script, but unfortunately got one issue with it. Don’t know why links doesn’t work when I’ve changed the # part in li element from

    Home

    to

    Home

    how can i fix this? And another question – what to do to make the active element selected when changing page from index.html to info.html (to avoid situation when in INFO subpage home element will be selected instead of info)…

    Thanks
    Eclipse

  • Eclipse

    in previous post html tags are gone… I wanted to change a href=”#” to a href=”info.html”…

    cheers

  • Eclipse

    ohhh I’m talking about lavalamp script 🙂 sorry

  • I’ve created a patch that fixes an (undocumented?) bug where you couldn’t have slides that contained lists. The code now defaults to first list inside the div wrapper.

    This patch also adds functionality to dynamically add slide buttons navigation that will allow you go to the next series of slides (if scroll is greater then 1 for example) so it’s a bit more powerful than btnGo. (Think the functionality on http://www.5bosses.com/examples/agile_carousel/multi_example/carousel.html with the blue dot navigation)

    Patch is at http://plugins.jquery.com/node/8199

  • @cardob (385)

    I had the same issue and got around it by using PHP’s getimagesize() function – this allows you to output the image dimensions on the fly, which in turn are used by the JS.

    Hope this helps

    Neil

  • Rasmus

    I found an issue when I had 17 slides, and set scroll to 5, then it wouldn’t show the last couple of slides. I fixed this by altering line 300 to:
    if(toitemLength) return;
    instead of:
    if(toitemLength-v) return;

  • cardob

    @ 393. BandsOnly.com (Neil)
    Thanks for the reply.
    For clarification – PHP’s getimagesize() function, would fix which problem? My having to refresh page for carousel to load and/OR being able to use images with different widths?
    Direction on where how/to place code would be a project/time saver.

  • Sonia

    How can I dynamically change the number of visible items depending on the user’s screen resolution? I seem unable to put anything other than a number, eg:

    visible: 6

    if I try something like this it just wont work at all:

    visible: getScreen() // function that returns a number depending on screen resolution

  • Hello Guys,

    first of all i like your jQuery Plugin very much, but i have a big Problem:

    How to addmore more than one jCarousel Light on one page??? It is possible and they appear, but when i use Next Button, all the jCarousel’s are scrolled! Buttons are named dynamically, so that they have other names for each Carousel Instance.

    Check out Demo: http://projects.4yourideas.de/werbelayer/demo.html

    I need urgend help.
    Thanks a lot.
    Sascha

  • Hello @Sonia,

    you cannot use a Function!
    What about declaring a variable like this:

    var TOTAL_NUMBER=getScreen();

    and then use:

    visbible: TOTAL_NUMBER

    ??? It works for me!

  • Ganeshji Marwaha

    @Sascha #397: You can create any number of carousels in a page. All you have to do is attach the correct buttons to the correct carousel. So, instead of using the class to identify a carousel, try using the ID to select a carousel and attach it to the right buttons

     

    @Rasmus, @Brendan, @Bob Ralian, and many others : Thanks for the fix and your effort to help fellow jquery community people. People like you and many others here who take the pain to not just fix an open source code but give it back to the community are the ones who make open source tick. Thanks a ton guys.

     

    Friends: I know, I haven’t been able to reply to many of your posts. I am sorry about that. It is primarily because, I have been too very busy with some other tasks at hand that is totally away from the S/W field. So, wasn’t able to get to it. Now, I am slowly getting back to it. Thanks a ton to all you guys who have been using jCarouselLite successfully and many more thanks to those who have been helping others get their problems solved. You guys prove why open source community thrives. You rock!

  • Mikhail

    Hi!

    Small problem can occur when circular is true and start is not 0. Carousel will move backward only for some time and then will glitch and start over without actually moving whole circle. I think best solution is to always count start of carousel in circular as 0.

    Best regards, Mikhail