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

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

  • can we stop the timer and reset it to start from zero? because my users click on the button “external control” and the control navigated to the selected item finely but the timer was counting and may be navigate to the next view in less than 10s “the default of my site” !!
    the second thing i want the autoscroll to stop when the user hover in the view ?
    the third and Finley, if there is more than one carousal in the page they were interpreting each of them, is there a way to get the page carry more than one carousal ?
    and thanks for a nice control .

  • Raghu

    Hi,

    I am looking to include this component in a website, I am building.
    1. Can I use this component under MIT license ?
    2. How do you use this component inside a website.. ?

  • jcarouselite

    Question:
    Why description disappears after have gone through a cycle?
    means the following a line have taken no effect:
    $(‘#channel-a-slideshow #desc’).html(a.slice(0,1).children().slice(1,3));

    Thanks !

    $(‘#channel-as-main-image’).jCarouselLite({
    visible: 5,
    btnNext: ‘#channel-as-bottom .next’,
    btnPrev: ‘#channel-as-bottom .prev’,
    auto: 2000,

    speed: 1000,
    beforeStart:function(a){
    a.removeClass(‘active’);
    },
    afterEnd: function(a){
    $(a[0]).addClass(‘active’);

    $(‘#channel-a-slideshow #desc’).html(a.slice(0,1).children().slice(1,3));
    $(‘#channel-a-slideshow img’).attr(‘src’, $(a[0]).children(‘a’).attr(‘href’) );
    }
    });

  • Hi Ganesh,
    I would so like to be able to use the variations of the carousel, but I only manage to get the code to work that you mention in step 3 of the installation. My knowledge of JavaScript ist minimal, I must admit. Would there be a way for people like me?
    Kind regards
    Mariam

  • SteliosF

    Hi Ganesh,

    I would like to know if it is possible to use more than one carousels in the same page.

    Thanks

  • SteliosF

    My problem has to by setting context to div in the following line.
    Removing div seems to fix the problem.
    if(!o.circular) {
    $(o.btnPrev + “,” + o.btnNext, div).removeClass(“disabled”);

  • Colette

    Hi

    For thos non-geeky ones among us, could you please make a demo pack. With all the bits and bobs included, so that is all works…and you don’t have to figure out what code goes where?

    I am struggling (as a non-geek) ๐Ÿ™

  • Andrew

    Just a tip, but when starting from slide 0, the ‘disabled’ class should be added to the btnPrev class/div.

  • erika

    Hello, I tried putting the carousel inside tabs. It works on first load of the page but when I choose the 2nd tab, I have to press refresh for it to load the carousel and when I go back to the first tab again, the carousel doesn’t show up unless I press refresh. Is there a way for them to load in tabs without pressing refresh all the time? Thanks a bunch in advance ๐Ÿ™‚

  • I’m trying to put a link but it’s not working. Even with the demo files. I just opened it and put a link on HREF tag but nothing.

    Any help???

  • The carousel creates 2 extra blank images at the end of the cycle. How do we remove?

  • Jacqueline

    Hello, can you help me with my jcarousel? I would like to add a zoom effect every time I would select an image. Can you suggest any?

  • Dennis Zaloznyy

    v1.0.1, line 239 has a bug: float is a js reserved keyword and needs to be in “” as in “float”. Please fix. Thank you!

  • ethanchen

    Geat works! But I find an issue that with” Scroll More” and “Non Circular”.
    for example:
    I have 9 items, when I use { scroll: 6, visible:6, circular: false }, the click button no works.
    And when I use add to 13 items, I could click only once, and it can’t show the 13th item.

  • Velten

    Hy, I have a recommendation for jCarouselLite:
    I wanted to combine two jCarouselLite’s and wanted to swap to the curr pos in the one I haven’t clicked in. To do so I had to change the functions beforeStart and afterEnd to:
    beforeStart(a, curr) and in Line 286 to:
    if(o.beforeStart)
    o.beforeStart.call(this, vis(), curr);

  • I can’t remember what the deal is with getting the carousel div to fill the width of it’s parent container. There are six slides of 151px width showing at any given time but the 6th (rightmost) slide is not visible. I have this working on another site just fine, and I can’t see that it could be anything other than my CSS. Can you advise, please?

  • Batman :)

    @ 1135. david b:

    I just ran into the same issue and implemented a quick’n’dirty hack.

    1.) If there’s only one item to display, show it statically and don’t initiallize the Carousel.
    2.) If there are two items, copy both of them, so the first one is at the third position and the second on the fourth of your array.

    Probably not the nicest solution, but works like a charme for me. ๐Ÿ™‚

    Cheers!

  • Maciej

    I have a “funny” issue of images/HTML elements not being initially displayed in each frame in IE7, showing only after any mouse movement over the page, described in more details here: http://stackoverflow.com/questions/6656233/jcarousel-lite-visible-frame-html-showing-only-on-mouse-move-in-ie7 Any (even the most generic) thoughts on this would be highly appreciated…

  • manoj

    hi sir i want to move scroll bar images left to right , its by default move right to left.

  • Rupak

    how can i use images for previous and next buttons

  • Daraul

    Hey, I’m working for a new company and one of our websites uses this plug-in for a scroller on it’s home page. I’m new here so I didn’t contruct the page, but it has problems and the guy who did build the page doesn’t know how to fix it (I don’t know how that is)

    Basically it looks like the order of the images is messed up. The scroller scrolls fine for about 4 images, then it jumps back one image, then starts going completely haywire. Basically jumping all over the place, with no apparent order. Has anyone else found this issue?

  • Velten

    Hy, you need to change:
    if(toitemLength-v) return;

    to:
    if(toitemLength+o.scroll-1-v) return;

    eventually you have to change some other code as well, but that solved my visible:8, scroll:4 Problem. Regards

  • Robert

    Hello,

    I love the work you have done on the jCarousel. I wonder if the support of showing more than one row has now been added?

    Thank you for you help on this in advance.

    Regards,

    Robert

  • Hello… can you please make a change that

    a) Includes the Width and Height of the contents in the atributtes passed in the function.

    I am getting some incoherent behaviours from these measurements because of margins and poaddings, and getting my head blown off by it.

    (will send this to your e-mail too)
    JPC

  • Adi

    Hi. Please help me.
    My carousel is “display” to “none”. But it crash the structure of carousel. I read that need to:
    “If in your css you hide the carousel by setting “display” to “none”, then the carousel will not have access to the appropriate dimensions and will result in faulty construction. To work-around this, try hiding the carousel using javascript after the carousel is constructed. That should solve the problem.”

    but when page is loaded then the carousel is flicking. A also read to fix that problem, I need:
    “Sometimes when you use a lot of images, then the carousel may appear to flicker while constructing itself. To work-around this, just add these style rules to the carousel’s div using your own css file. That should solve your problem.
    .carousel {
    position: relative;
    visibility: hidden;
    left: -5000px;
    }

    But it doesnt work! How can i solve this problem? Thanks a lot!!

  • Ma

    What license this plgin use

  • kosta

    I use 5 divs as carousel units. but it renders only 3 divs correctly. other 2 divs content(text) is displayed on the top of page. please help

  • Anthony DePalma

    I am not sure if this issue has been mentioned, but I have a carousel that is not circular, and has a dynamic number of elements. I can display 7 on the screen at one time, however any more than that and I invoke your carousel.

    The problem is that I would like to set the scroll higher than 1, but it will only work if there are exactly that many elements left over. For instance if I set the scroll to 5, and I have 7 elements on screen and 4 more to the right, I can’t scroll to the right at all. I imagine there just needs to be some check to scroll to the end if there are fewer items than the scroll amount. Thanks

  • You made some good plugin there. I did a search on this script and found most people will agree with your plugins.

  • Benjoarc

    This plugin doesn’t work with Fancybox jquery plugin ๐Ÿ™

  • i want 4 pics in slider front. i try to adjust width but its not working plz help me for this.

  • hey Benjoarc it seems that jquery is conflicting with facnybox plugin. the fancybox jquery may be also use some javascript function. use jquery.noconflict();.

  • Hi Ganesh
    Wonder if you can point me in the right direction: I’m trying to implement the carousel on a form page. We’ll have 6-10 items (email template selector), of which we’ll show three.
    I’m using ‘circular: false’ as our web engine does not like the extra items added and blow a security error.

    THE PROBLEM IS that when you get to the end of the slide and click .next one more time, it submits the form. I’ve tried binding a ‘return false;’ to the buttons, but it is not working.

    Thanks in advance.

  • om

    It is good plugin but sorry to say i am not able to use because it does not support add element at run time.

  • om

    please suggest is there any way to add run time elements

  • Aiia

    Hi Ganeshji,
    excellent work!
    After some experiments with Lite I found just one drawback – it doesn’t mark “current” position in pagination items – only with it pagination could be used nicely.
    Thx ๐Ÿ™‚

  • Hi dear i am using your jquery-plugin java file but update it using your latest version file but i have one problem with that on running website carousel showing half part of picture and other missing here i m giving you screen shot.http://imageshack.us/photo/my-images/26/carouselproblempic.png/
    Please solution my problem.

    Thanks

  • Nancy

    Is it possible to have a fade effect for the transition in the auto scroll?

  • Hi,

    I’m having a strange problem with jCarouselLite 1.0.1. I’ve created a page with 30 pictures (10 across and 3 down). Each picture has a caption beneath it. Everything scrolls correctly but the problem is, when the page first loads, it displays everything EXCEPT the captions for the bottom row. If you refresh (click F5), the page reloads and displays everything! It’s happening on both IE8 and FF5.

    The page is at: http://www.finerwoodworking.com/portfolio.php.

    Any help is appreciated!

    Thanks,
    Gary

  • Looks like I’ve found the “problem”. I had to specify the height of each image as an HTML attribute instead of a CSS style (height=’***’ instead of style=’height: ***px;’). By making that change, everything now displays when the page first loads.

    Gary

  • Roberto Osorio

    Hi Ganeshji!

    I am updating a site that uses your jCarousel lite to display new items on a website, however the spacing between items seem to be uneven at some instances. For example there might be 5 news items with even spacing between them, but the sixth one has a bit of additional space separating it form the previous item. Any ideas on why this might be happening?

    Here’s the site: http://clients.magnumultimedia.com/nihcsr/staging/default.htm (bottom right corner).

    Your feedback would be greatly appreciated.

  • Works wonderful (jcarousellite_1.0.1.min) in FF Safari Chrome but Ie8 – it puts a black background and doesnt fill the area correctly – I been messing with this for 3 days and hunting for an answer HELP please!

  • hi,

    jCarousel so cool, there is a little thing i want talk to you.

    when i set jCarousel Parameter auto & btnGo. is there any way to set btnGo current style? and be sure working Synchronization with auto slide~

    thx^!^

  • Chamath

    I’m using three sliders. I want to know which one click by the user. Is there any way get clicked class?
    eg:

    I’m calling it like this.

    $(function() {
    $(“.thumb”).jCarouselLite({
    btnNext: “.next2”,
    btnPrev: “.prev2”,
    visible: 13,
    circular: false,
    speed: 500
    });
    });

    $(function() {
    $(“.image”).jCarouselLite({
    btnNext: “.next3”,
    btnPrev: “.prev3”,
    visible: 1,
    speed: 800
    });
    });

    $(function() {
    $(“.images”).jCarouselLite({
    btnNext: “.next3”,
    btnPrev: “.prev3”,
    visible: 3,
    scroll: 3,
    speed: 800
    });
    });

    Thanks,
    Chamath

  • I like this blog. It is a rich content topic. It helps me solve a lot of problems. It updates at a very fast rate, and provides for me many opportunities. I think it can help me to solve many problems, thank you.
    Oh! It’s really good! Thank you!
    evening dresses
    strapless prom dresses
    cocktail dresses

  • HI Ganesh. Nice plugin. I’m using it in a custom built WordPress site and have run into a slight issue. I am building a custom post type that can have list elements in the content (post_content) but when I try and push them into the .anyclass ul li content the list elements are being picked up by the carousel JS and rendering as extra elements.

    For instance in a 3 item set I placed an alert(tl) just below var div = … and got 3 out as expected. When I placed the content into the LI elements I got 9 as my alert.

    Is there any way around the issue of including LI elements in the content of the anyClass li’s?

  • @Chamath: Can you not get the element clicked using jQuery? $(this).clicked? and work out which of the prev/next buttons was clicked? Maybe give an ID to the buttons that have something in common with the slider they control?

    Rob

  • @Ganesh: Managed to solve the issue by editing the JS slightly to target a ul with a class element and each LI in that UL has a class also. This seems to have fixed the issue with pulling any content LI elements into the generated list.

    Rob

  • very nice post
    thanks