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

  • Wes Pomeroy

    Whoops…forgot to mention the URL where you can see the wackiness in action:

    http://72.29.74.123/~crvnnet/wes/variax/

  • Ganesh

    Thanks for this plug in. But I have two problems going on at the moment. The situation is currently existing on my home page at kerryonworld.com on the KOW! Discussions section.

    First problem: Empty slide and skipping problem
    ———————————————–
    Use Firefox 3.6.10 current version. Watch the KOW! Discussion section on my home page. Notice that there is a blank entry after reaching the 3rd item (this is the last – there’s only 3).

    There is a skipping problem as well as it skips past the first item very quickly onto item 2. I’ve seen this happen in IE 9 beta and Safari 5.01 Under Opera 10.62 (current build) this doesn’t happen. So this appears to be a problem in general.

    Second problem: Incorrect block height rendering
    ————————————————–

    Under Safari, notice that the height of the plugin is too small. Under Opera it renders to the correct height. Under Firefox and IE 9 beta there is way too much white space. This may not be JCarouselLite’s problem but if anyone can explain how to fix this problem that would be great.

  • hello i have one problem…i want to scroll vertical image scroll er continually when i mouseover on the button….can you please tell me the solution

  • arzuk

    hello, how i can modify the autoscroll option after a object initialization ?
    thank you.

  • Hks

    When you have more than 8 wheel and when you have less than 8
    This code works perfectly in FF Chrome Safari
    But in IE6 and IE7 is not running …

    _______
    Code:

    $(function() {

    var n = $(“.boxLogos ul li”).length;

    if (n > 8) {
    $(“.boxLogos”).jCarouselLite({
    auto: 1000,
    speed: 3000,
    easing: “bounceout”,
    visible: 8,
    });
    };
    });
    ________
    Anyone know how to fix?
    Sorry my english ;D

  • Hey there!

    Thank you again for creating this plugin. I am having the same issue that Wes was having (comment 952). Did you ever find a solution to this? Thank you so much in advance for the help.

    Michael

  • Hello,

    I tried searching your blog for the answer to my problem, but could not find it.

    The problem occurs when circular is true. As the carousel loops past one iteration, the css stops working. Have you seen this before?

    Thanks, Todd

  • Hey Ginesh,

    I figured out the problem I was having (comment 958). The event:

    if(o.btnNext)
    $(o.btnNext).click(function() {
    return go(curr+o.scroll);
    });

    was concatenating the “curr” and “o.scroll” buttons. I forced the integer type by adding a “-0” before the “+o.scroll”.

    Making the eventual code:

    Hey Ginesh,

    I figured out the problem. The event:

    if(o.btnNext)
    $(o.btnNext).click(function() {
    return go(curr-0+o.scroll);
    });

  • could you please include html sources of demos along with js sources on the example pages. since they’re ajaxed and it’s not too easy to take and test it fast. and ty very much for the plugin!!!

  • j

    My list is populated automaticaly from a db. I’ve made a small change to disable the autoscroll if the amount of items in the list is less than or equal to the visible parameter.

    if ($(“li”, ul).size() <= v) {
    o.auto = null;
    }
    else {
    if(o.circular) {
    ul.prepend(tLi.slice(tl-v+1).clone())
    .append(tLi.slice(0,o.scroll).clone());
    o.start += v-1;
    }
    }

  • Michael

    Hello, I’ve implemented the jcarousel on my website.. and it works great.. the only problem is that it breaks the fancybox which is another great script.. do you know a way around it? thanks

    Michael

  • Great script ๐Ÿ™‚

  • I used your code thank u

  • Nice! Now I know what to do, thank you! And as this information is educational so this site has been added to my RSS feed for later browsing. To know more about
    marathon training

  • gtvitini

    Hello,

    First off, this plugin is my favorite one.

    However, there seems to be a problem I can’t solve. I am using it to slide vertical 8 li elements of a list. The information contained on those elements are just link items returned by a previous query to the database.

    But, even if the items are preconstructed, every time a new item is slided up and replaced by the next one, I get a flickering of the mouse pointer. Finally, when all 8 items are slided for the first time, the mouse pointer stops flickering.

    Any ideas???

  • Ben

    Hi There,

    This plugin is very nice however I have been having problems in non-circular mode. There is a bug where external buttons will not hide when there are no more slides to scroll to.

    I have fixed this however. Here is the full pastebin.

    http://pastebin.com/2SX7kJQJ

    Basically I changed the !o.circular if statement to this:

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

    However when the page is loaded they would not hide correctly since go(to) is never called. I simply added a variable ‘loaded’ to the o object and called go(o.start) when loaded is false….

    if(!o.loaded) {
    go(o.start);
    o.loaded = true;
    }

    I hope this helps anyone having similar problems. I would like this fix to be included into the next release and I’m happy to help with testing etc.

  • Ben

    Michael from comment #963,

    This is because you need to call the fancybox/lightbox constructor after you have called the jcarousel constructor.

    jCarousel, in circular mode, appends additional list items to the DOM. Fancybox is bound to the current elements in the DOM. Any elements added (by jcarousel) will not have fancybox bound to the click event.

    So just do something like this:

    $(‘.gallery .slides’).jCarouselLite({
    //your options here…
    });

    $(‘.overlay’).fancybox({
    // your options here..
    });

  • Gabi

    Hi

    I’m new to all this web publishing and I am trying to use the jCarouselLite but everytime I try and publish my webpage it asks me the security question of installing script or active x controls, I notice on all the demo web pages this does not happen.

    What have I done wrong?

  • Really trustworthy blog.. Its also informative information. Thanks for the post and assimilation in adequate others.

  • for the solution on 960 – do you have a live post of the fix? I did exactly what you did but I’m still getting the same bug as 952. Are you sure that’s the only thing you modified???

    Thanks

  • I think I found the issue – I was using $(document).ready(function() in my script. So I removed that and went back to basics and used the original code…

    $(function() {
    $(“.anyClass”).jCarouselLite({
    btnNext: “.nextb”,
    btnPrev: “.prevb”
    });
    });

    and it works! Nice project!

  • fao

    Hi, nice carousel

    there is a way to display half of the image on each side ? Something like Fraction Configuration but each side ?

  • richard

    Hi, This is a great plugin thanks for sharing. I have been playing around with it and I have only one question is it possible to change what item is being displayed by an external javascript call. For example I want to bind this to a drop down box so when the value changes in the dropdown box the displayed image in the carousel also changes.

    I had a look at the button go but I could not see a way to use this.

    Thanks for the help.

    Richard

  • Maya

    Wow, you are SO COOL for doing this SUPER UBER COOL plugin… but, was it too much effort writing a SIMPLE and CLEAR (and minimal) demo page for us idiots, who are not as cool as you are? Oh and no, your demos are all but simple and clear.

  • pinocchio

    Hi
    I’m using RTL wordpress. I have bought Classipress which uses jCarousel Lite for showing ads on the header. in LTR mode there’s no problem but in RTL there r some problems!!!! I have solved some of them but it still is bothering! I set the num of visible items to 5. there r 5 ads showing as the page loaded it moves to right 5 times then all disappear!!! after several 2nds it starts appending from left 1 by 1 !!! I want it circular in automatic style ! since I’m not a pro and just a newbie I don’t know how to modify it in order to make it work! ‘s very very nice of u to help me

  • santaclaus21

    It’s really crap. I was trying to run it with jquery.1.4.2 for aprox 7 days. Sometimes i’ve seen pictures, sometimes not e.g. after refresh (IE, FF). Firebug don’t show any problem. In Google Chrome everything was working fine. I made thousends of changes (width/height of elements, divs, looking up for solution on this forum) unfortunetly.
    I’ve tried run it on jquery.1.2 and it’s ok, but I have to use latest jquery (other function on site).

    And now I’ve tried to use full jcarousel (not lite) and everything is working fine… so I think that jcarousellite MUST be updated.

  • santaclaus21

    P.S. I should add. that I’m using iframed content. body > iframe > body > table > div.jcarousellite. I can’t find any good solution. First loading mainly is fine (FF), after refresh “div.jcarousellite” is empty (script fail).

  • santaclaus21

    I’m trying to find a solution…
    after: var liSize = o.vertical ? height(li) : width(li);

    I’ve made alert(liSize); FF returns: 0, gChrome: 152 it’s a point. I’d like to use lite smaller version…

  • santaclaus21

    I suppose that #942 will resolve a problem. Methods height() and width() are not working in my case (IE,FF) but .css(‘width’) or .css(‘height’) is fine. I think that this should work for me.

  • santaclaus21

    So, I’ve changed these methods. It’s working now (even inside iframe), but width/height (also margin) of div/img/il must be declared inside code (not in css file).

    Working files:
    compressed: http://wojtek.klaster.net/javascripts/jcarousellite.js
    uncompressed: http://wojtek.klaster.net/javascripts/jcarousellite_uncompressed.js

    Enjoy…

  • Charly

    jCarouselLite and the jQuery ui sortable interaction are conflicting : jCarousel elements don’t slide.

  • Richard

    I must echo comment 978 – and am glad I got confirmation that I’m not the only one with this. I found in fact that it’s IE6 & 7 that have eht problem – IE8 and FF were OK, but IE6/7 causes some of the LIs to not show in about 50% of occasions. Tried stripping it down to bare simple text, but no joy. I do hope you can get it running with jquery 1.4.2, as it’s a great little plugin – but I acn understand the pain of having to keep up with all the changes in jquery all the time.

  • fao

    are there a way in afterEnd function to known which button (prev or next) was clicked ?

  • Hi Dear…. Here I see a good strategy in your post.
    Thanks for sharing such kind of great tips, keep it going, hope you can share more!

  • kevin

    This is awesome, except the next and previous buttons are way too confusing and not easy to move around and Im not seeing where I can find how to custom them. Is there a spot that Im not reading? is there a way to float the buttons over top the pictures and replace the “>>” and “<<" with images? anyone else have this problem?

  • starmonkey

    HTML content doesn’t support list items – breaks the carousel code. Eg your ‘Non-Image Content’.

    Considering a carousel is a kind of “presentation”, I would have thought support for LI’s is important?

  • Kevin

    n/m to comment 987 – i moved some things around and it works.still kind of a pain

  • Kevin

    scratch that – code that is provided for us breaks in chrome and Safari. The examples work that are on the front page and demo but when you take the code it doesn’t work. Im guessing there are files that are used on those pages other than the 1’s provided on the installation page

  • Its one of my favorite post. Its also helpful topic for newbie. Park City Vacation Homes. Thanks a lot for informative information.

  • phvincent

    Hi All and Ganesh !

    Great job for this plugin. It helps me in designing my client’s website. However i’ve got an issue using IE6/7 (i didn’t test yet with IE8) : before the div containing the jCarouselLite, i have a series of css vertical pull down menus (using simple nested with display:none when off and display:block when hovering the main menu). The issue is that my vert menus always appear behind the carousel and not in front of it !!! My menus have a z-index:200 but since the carousel has a position:relative and a z-index:1, it breaks the flow. Curiously, FF treats my menus correctly: they’re always on top of the screen.

    Did you ever seen this problem and any idea to solve?
    Thanks for helping us

  • phvincent

    Sorry, my last post lacks a couple of words: you should read “using simple nested UL LI tags…

  • sanaclaus21

    You can change vales of z-index used in jcarousel. Try to edit uncompressed file and at the finish compress it. Done. ๐Ÿ™‚

  • Not sure if the issue I am having is with jcarousel or with something in Draggable in jQuery. Code works as expected in IE and in FF, but Safari is giving me fits when dragging items that are in the carousel. For some reason when I drag a carousel item the drag stays active even after I let go of the mouse. Any ideas? Oh and before I forget, your carousel saved me a massive amount of development time!

  • I’m having trouble with IE 8. In “compatibility view” it is only showing half of the image in the carousel with no controls to page through the slides. It seems to appear ok in Chrome, Firefox, Safari and IE 8 regular view. It’s the homepage here: http://www.coastalpet.com. Any ideas?

  • Shaun

    Hi and thank you for this excellent plugin!

    I am using the plugin to auto scroll through a list of names but I was wanting to increase the font size of the name it stops on each time, and then return the font size to normal when it moves onto the next name.

    Has anyone done something similar with this plugin or has any ideas how to achieve this?

    Thanks in advance,

  • Daniel

    Hi, great plugin & documentation.

    Is it possible to have more than one carousel on the same page?
    I tried 2 carousels with a unique id, passing a dynamic id to the script, however the controls of each carousel affect both carousels at once – any idea if this is possible?
    thanks!

  • Daniel

    Hi Ganeshji
    sorry for my previous pointless question – just went over previous posts and saw you already answered this.
    thanks again for sharing – this is a great plugin

  • I just couldnt go out of from your blog post before saying i certainly loved the quality information that you offer to your readers… Will be returning frequently to check up on unique stuff you publish!

  • chris

    good job…

    i want to have a form field showing the slide number(index)

    so each time the slide changes so does the form field

    thanks

  • Hi,
    There is a minor issue with IE7 when setting the carousel vertical. The amount of scrolling is different than the real height of the li container. I have to disable my carousel for IE7 users. A fix for this issue would be really appreciated. I have seen other user complaining about the same issue.

    You can easily reproduce the problem with the vertical demo and IE 7.

    Thank you very much for your work. Very good job.