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

  • DavidG

    I have jCarouselLite installed on a web site and its working perfectly. Thanks very much for the script.

    What would be the best way of making this degrade gracefully for browsers where javascript is disabled?

  • Christopher J. Bottaro

    If you set circular=false and scroll=2 and you have a carousel with 10 items (and the default visible=3), it will not scroll to the last item. It sets your btnPrev to disabled on the last set of 3. Please help. Thanks.

  • Christian

    Hi!

    Nice Script!
    But how do i handle multiple carousels on the same page?

    Maybe you can answer here and via mail. thx.

  • Christian

    Hi!

    Ok, i have found it. ๐Ÿ˜‰

  • simon

    i have the carousel set to auto-scroll, but is there a way to make it pause on mouse-over?

  • Vicky

    I was able to do mouse over hoover. try this link for information on how to do this (updated JS file) http://groups.google.com/group/jquery-en/browse_thread/thread/e17a69e83d7e4f30/79eb0d45dd70af19?hide_quotes=no

  • Hi, I have implemented three carousel using a single script on the above url of my working site, but there seems to be some problem in IE 6 regarding to the position.
    please open the site in IE 6 and you would see that the content of first carousel in welcome box would go to the bottom of the page. I tried to solve this by removing relative position from ul.css and div.css in the script , by doing this it bring the content back to its position but srolling works no more.
    so Please help me .

  • Kevin

    Im developing a site and im trying to get it working on an ASP page, the images show-up but in a row downwards and i copied and paste the code snippets and linked them up. I can’t find out why its displaying the pictures the way they are

  • SeC

    Hi.
    When using visible with float part as ‘4.5’ when scrolled to end, last item is only visible “in half” and I cannot scroll to it with btnNext.

  • Hi there,

    First of all, let me thank you for a great jQuery plugin.

    Now, I mainly use this plugin for HTML content. However, when I use a nested HTML list as content, I think the plugin tries to change this to another Carousel, when this is NOT what I want.

    I’d like to display any sub lists as normal.

    Is there any way to get around this? Almost seems like jCarousel is being recursive, but I’m not too good with JavaScript.

    Many thanks.
    Mikey.

  • Kevin

    nevermind from my comment 2 posts ago, i got it to work, i just had to copy the code you had line for line and then change it up

  • Kevin

    sorry I just thought of another question

    -Do you know of any other JavaScript to have text over the pictures??

    -Also I’d also like to thank you for this code, all of the other ones I’ve found don’t do the full circular motion, they either stop or shoot past all the pictures back to the first and vice versa

  • @Kevin

    You don’t need JavaScript to layer text over an image. Absolute positioning with CSS is the best way to achieve this.

  • Othmane

    Good morning, thank you very much for your work.

    I have a probleme althouth I downoad the last jcarousellite.js

    I use Auto, but I have the bug you talk about. At the last picture, it restarts and dont’t seem to continue.

    Can you help me please.

    My code is :

    $(function() {
    $(“.auto”).jCarouselLite({

    auto: 800,
    speed: 1000,
    mouseWheel: true,
    visible: 4,
    start: 0,
    circular: true,
    easing: “bounceout”

    });
    });

    Document sans nom

  • Kevin

    @Unibands

    thanks, my only question is, is it going to mess up the ‘s at all?

    say I have 3 rotating images and each image has different text how would i write the html for the text that is going to be absolute positioning? sorry im new with the whole JavaScript writing

  • Thanks for your admirable work! This is really a great plugin. Regards.

  • Mark

    Thank you for the amazing work ! One of the best jquery bang-for-weight plugins i’ve seen yet !
    I’m also having issues with nested jcarousellites.
    I’m trying to use a “macro” carousel as tab navigation with some of the tab contents containing a carousel for images and other tabs containing nested UL’s . Seems like jcarousellite is going recursive on all child entities of the the marco UL rather than acting only on sibling that directly descent from the macro jcarousel. Hope that makes sense..

    Any suggested fix ?

    Thanks a million !
    M

  • Hey, have you seen any issues with using jCarouselLite AND Fyneworks’ jQuery Star-Rating-Plugin on the same site? I seem to be getting conflicts.

    http://www.fyneworks.com/jquery/star-rating/

    Either script alone works fine, but not both on the same site.

    Thanks!

  • I have it working on my wordpress site, but am having the image flickering problem when the carousel scrolls, especially with firefox 3.5. I tried implementing your fixes listed on the known issues page, but it just made the whole carousel dissapear. Can you please give me some additional info on how to accomplish the fix?

    THANKS!

  • Greg

    First and foremost, this is a great plugin (especially for a JS novice like myself)! Next, I have the plugin working fine but I am having an issue adding a second carousel at a smaller size (that works independently) on the same page. Right now the images are all showing and stacked on one another. I read through the comments and will be trying to use the suggestions to get the next and previous buttons to work independently. Main question – is what I’m trying to achieve even possible?

    All suggestions would be greatly appreciated. THANKS!

  • Franc y

    Hi,

    first of all – thanks a lot for this great plugin, which is very easy to use.

    I just have a question, whether it is possible to select an image.
    That means I show only 3 images (visible: 3) and now I want to add effects to the first, second, and third image, which are visible.
    First, second and third image will get a different effect (jQuery.rotate plugin)
    My idea was:
    afterEnd: function(a)
    {
    (‘#img_first’).rotate(10);
    (‘#img_second’).rotate(10);

    }
    I just don’t know what to replace for $(‘#img_’)

    Thank you!

  • Mark

    Would be good if there was an easy way to ‘focus’ on the middle image of say 3 visible. Maybe fading out the others slightly and some pre-defined content relating to the focus image triggered in an external div. Would make this much more useful.

    Has anyone done anything similar?

  • I agree with mark. that would indeed be easy

  • Hello, there. I am running your plugin on my homepage at http://thelearningcurveplus.com/. Even though I altered the jcarousel file to slow down the slider, it still won’t slow down! Do you have any tips? I want slides to change every 20 seconds.

  • Pardeep

    there should be disable of button image when image end at right and left so user must know images got end so click left button to scroll

  • Aaron

    Is there a way to not use an unordered list and just use divs with content?

    So instead of ul and li you could have

    JCAROUSEL DIV

    BEGINING DIV
    TABLE
    CLOSING DIV

    BEGINING DIV
    TABLE
    CLOSING DIV

    JCAROUSEL CLOSING DIV

  • Susan

    Hi

    Is it possible to make the images have links on them? I would like to be able to click on the image and link to a description page.

    Thanks

  • Jacopo Facchini

    Hi, very nice plug-in.
    It has a little problem, if you use a flash in a slot of the carousel, with firefox 3.5.7 it is dislayed several times.

    Thank you

  • M. Jebamalai Jaya Chitra

    How to stop scrolling on mouse over?

  • Duane Livingstone

    hey there,

    nice plug-in…clean and simple.

    I have one issue though. lets say that you set “visible: 4 and scroll: 4” and i happen to enter 9 items, it will display items 1-4, then 5-8, then it will display the next 4 items (i.e. items 9-3). Once it reaches this point however, the animation jumps back to 1 and scrolls right away instead of just continuing the scroll sequence.

    This forces you to always have multiples of the number of items that you scrolling at a time…any suggestions?

    Thank you.

  • mario

    Hi, I have problems with scrolling more then on item at the time, when I switch off the circular option. For example I show 7 from 11 images and set scroll to 3. After click next i see image 4 to 10 and it is no longer possible to see image 11… How can I change this?

  • Doesnt work when placed inside a table cell. why is this?

  • mario

    I think I have found a solution for scrolling more then one item. I just set the positions to 0 or to the end of the array of images…

    This is my code around line 298 to 305 or something…

    // If “scroll” > 1, then the “to” might not be equal to the condition; it can be greater depending on the number of elements.
    curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
    } else curr = to;
    } else { // If non-circular and to points to first or last, we just return.
    if(toitemLength-v) {
    curr = itemLength-v;
    } else curr = to;
    //if(toitemLength-v) return;
    //else curr = to;
    } // If neither overrides it, the curr will still be “to” and we can proceed.

  • Matt

    @Susan
    To make images link to another page you just need to wrap the image tag with a standard
    Here’s an example:

    And for anyone interested, an example of adding a title above each image:
    Picture Title
    For this I used some CSS styling (where class=”carousel” in the main DIV html):
    .carousel {
    font-family: tahoma, arial, sans-serif;
    font-size: 0.8em;
    color: black;
    background: white;
    border: 1px solid black; // border around each image
    text-align: center; // text position above image
    }
    .carousel p {
    margin-bottom: 0px; // sets distance between text and image
    margin-top: 0px; // for non IE browsers
    }

  • Matt

    Ok, my html has been stripped out of that last post.
    I’ll try it another way:

    [sourcecode language=”css”]

    [/sourcecode]

    and…

    [sourcecode language=”css”]
    Image Title
    [/sourcecode]

  • Danny

    Hi Ganesh,

    I need to make the carousel flexible, it needs to flex when the resolution goes up or down. Is there an option which i can use to do this?

  • Hi Ganesh,

    Jcarousellite has stopped working on a siet that we host. We’ve checked that the include paths are correct, but it seems to be throwing the following javascript error:

    $ is not defined

    I can send you the URL if that helps.

    Nothing has changed except that both PHP and MySQL were upgraded to latest versions recently.

    Any ideas ?

    Thanks

    Nick

  • Have a problem trying to generate dynamic carousels.

    I have attached a click event to a button which uses ajax to get a number of elements to place into the dom within the carousel .

    At this time, the carousel is hidden, but once the html is inserted, I make it visible so construction should work ok.

    Once visible, I call the contructor, but it fails with this error:

    Javascript Error: el[0] is undefined (line 335 of full script)

    My code:

    // add click event to ingredient image for image browsing carousel
    $(“#add_ingredient_image”).click(function(){
    // update images to show in carousel – generates a number of
    // lines and puts in correct div
    $.post(“generate_ingredient_image_html”, function(data){
    myhtml = eval(data) ;
    $(“#ingredient_image_carousel”).html(myhtml);
    // show before construction to avoid issues
    $(“#ingredient_image_carousel_wrapper”).fadeIn(5000,function(){
    // construct once faded in
    $(“#ingredient_image_carousel”).jCarouselLite({
    btnNext: “.next”,
    btnPrev: “.prev”
    });
    });

    });
    });

    Hope you can help! Dynamic carousel creation with this small plugin would be great!

    Bob.

  • @Nick Roper

    If Ganesh hasn’t gotten back to you yet about your problem, check that your path to jQuery is correct, because that is what is causing your error. not carousel.

  • Hi, just trying this out. Though I’ve come across a couple of flaws in it. They’re mentioned above, but I’d like to cast my vote in favour of fixing them!
    1) If you set visible:x, and scroll:x, and circular:false then the carousel wont scroll to the last item. I assume that it would work if the number of items was a multiple of x. But if it’s not then the carousel wont scroll to the last item(s) because it instists on only scrolling x items at a time, even if there are fewer than x items left to view.
    2) It would be nice if it returned false on the click event for the next and prev buttons. That way it would make it easier to have it degrade gracefully, as those buttons could actually be links which the carousel just overrides.

    Cheers
    Adam

  • Hi, just trying this out. Though I’ve come across a couple of flaws in it. They’re mentioned above, but I’d like to cast my vote in favour of fixing them!
    1) If you set visible:x, and scroll:x, and circular:false then the carousel wont scroll to the last item. I assume that it would work if the number of items was a multiple of x. But if it’s not then the carousel wont scroll to the last item(s) because it instists on only scrolling x items at a time, even if there are fewer than x items left to view.
    2) It would be nice if it returned false on the click event for the next and prev buttons. That way it would make it easier to have it degrade gracefully, as those buttons could actually be links which the carousel just overrides.

    Cheers
    Adam

  • Dee

    Hi, my slide doesn’t always load fully, in fact it doesn’t load fully most times. You have to refresh the page and sometimes several times to see the full slide. It looks cropped. This happens in both Firefox and IE. Please look at the this pic http://img85.imageshack.us/img85/9150/jcissue.jpg to see what I’m talking about. How do I prevent this from happening? Thanks.

  • David

    Why does jCarousel create clones of the slides? It makes it impossible to use server controls (e.g. ASP.Net) inside of the slide containers. Controls, regardless of language/technology used, should always have unique ID’s. However, when you create clones of the slides, it clones everything inside of them as well. Thus creating duplicate ID’s and breaking server controls and web standards.

    Would love to know if there is a work-around for this, or if it’s just “take it or leave it”. It’s a really nice plug-in – would hate to abonden it.

    Thanks in advance – David

  • Steve

    Hi.

    Sorry but i do not know where to add the trigger function shown in the instructions as part 3?

    Can you please add a working example that allows me to look at the code.

    regards

  • Phil

    I am using this to create a vertical news ticker.
    It is cutting off the words after the 4th sentance.
    Is there a way to control this?
    (Basically the height of the li
    THanks

  • yunminglin

    I am using this to create a picture slider
    Now I has a problem to devide the visibal num into 2 line,not just one line
    How can I do?

  • Lorenzo

    Hi there thanks for jCarouselLite. I have a problem with a simple scroll with a single panel that says “Uncaught TypeError: Object # has no method ‘jCarouselLite'”. Where can be the problem?

    This is my code definition:

    (‘.panel_style’).jCarouselLite({
    btnNext: “.bd”,
    btnPrev: “.ba” ,
    btnGo: [
    “.conteo_style .b1”,
    “.conteo_style .b2”,
    “.conteo_style .b3”,
    “.conteo_style .b4”
    ],
    visible:1,
    scroll: 1
    });

    Thanks,
    Lorenzo

  • Thomas

    Hi,

    Would it be possible to set a cookie to remember currently selected menu item?

    Thanks for a really good (and small!) plugin ๐Ÿ™‚

  • Amazing code … thanks!

    Small problem … I have some spacing between my items:

    http://www.realkana.com/iphone/

    When it scrolls, the (blank) space below the last item is included in the scroll region, so the new item that’s scrolling up into position appears before I want it to. Is there any way to work around this? I tried a few CSS ideas but failed ๐Ÿ™

    Let me know if the above isn’t clear … a bit hard to describe.

  • Hello there. I used jCrousel Lite to create the following slider: http://e-ast.ro/ , you can see that on the top of the page. What I want to know is how could I change the code to make the carousel stop at the precise moment I mouse-over it.
    Right now it does stop but only after the next photo in line disappears from the slider.