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

  • Ginesh

    Excellent one. But there is a bug in this. The following setting will allow just 1 ‘Next’ moves. But it should allow 2 next moves.

    There are 11 items in Li.

    $(function() {
    $(“.playlists”).jCarouselLite({
    btnNext: “.right”,
    btnPrev: “.left”,
    circular: false,
    visible: 4,
    scroll: 4,
    speed: 800
    });
    });

    It will display only 8 items.How to solve it?
    “scroll: 1” means it will display 11 items. Any idea?

  • Maria

    I am using it with wordpress and its not working. not giving any error but still not working.

    Is there any conflict in it with WooThemes or wordpress?

    Thanks,

    Maria

  • Just to notice that I was looking for a way to stop (onmouseover) and restart (onmouseout) the autoscroll.

    I found a patch to your plugin there : http://github.com/kswedberg/jquery-carousel-lite/blob/master/jcarousellite.js

    it provide with pauseCarousel and resumeCarousel triggers…

    Please update your code with it, as well as documentation on site.

    Best regards and congratulation for your work,
    Edouard

  • James

    I am having problems with creating the stylesheet and also the carousel controls. I can’t seem to get it to work properly.

    Can anyone give me some help. I want it exactly as the same on the front page ?

  • I’m having an issue in IE7 where the images inside the carousel don’t display until i mouseover the prev or next button. I’m using a sprite for the background image and have also incorporated a sliding boxes functionality for captions.

    All other browsers are displaying ok, although IE6 is broken by the sliding boxes add-on. Any ideas as to why It’s not displaying correctly on page load in IE7?

    Thanks!

  • James

    I am having problems getting it to work with other JQuery code including one for tabs and a content slider ?

    Thanks

  • Thanks for your good work. Is jCarousel Lite compatible with slimbox, too?

  • cc

    I want to add and pause play button

  • howard

    How do i get rid of this annoying popup of jcarousel?
    Thanks for any advice

  • Ivan

    Hello,
    I have a little problem using jCarouselLite with jQuery UI Calendar: seems that the text contained in the jCarouselLite news scroller appears on top of the Calendar, as shown in the screenshot here: http://www.ivanhalen.com/overlay.jpg
    Is there a workaround for this, please?
    Thanks…

  • maofree
  • pemi

    i really like it but:

    1) really needs the option stopOnMouseOver: true,
    (one of links above makes this one possible)
    2) would be great to make scrolling workable too by onmouseover
    (sides of the wrapper div would cause the scrolling on over)
    – have not found solution to this one so far

  • frankAb

    I’ve been searching for a couple of days so far to fine a solution how to center the Imageslider ๐Ÿ˜› Well it’s not done yet, as I let create the items dynamically, the “margin: 0 auto” does not work. Only when I resize the window, open Firebug or save the HTML-File, then everything is fine, but not right after loading the page.
    Is there any “CSS”-crack around being able to help me with this issue?
    My testpage can be found at http://jagas.de/rm/weiss/making_of.html

    thx in advance ๐Ÿ˜‰

  • Hi. I love this piece of code but have a problem. I want to include a list of links (ul) within the actual carousel but this causes problems with the basic functionality of the plugin because it searched for li. Is there any way around this?

  • Chris

    When using the external controls, is there way to have the control number highlight when that image is visible.

    I am showing one image at a time and made a static and active image for the external control. I would like the active image to display on the numbered image that is visible.

    Is this possible to incorporate with this plugin?

    Thank you in advance for any help,
    Chris

  • atheeq

    Hi,

    I am using tabs with slider. if i click same tabs twice then that images become twice.Why its is happening like .
    Kindly reply me back

    by
    atheeq.

  • Great job so far but I have a problem and I hope, that you can help me. If the number of list-items is smaller than paramter “visible” the scroll function doesn`t work correctly. I use a “related post”-plugin, in which the number of list-items in each post is unknown. If I set the parameter “visible” to 3 for example and the plugin outputs only two items, the scroll-function doesn`t work correctly because the height is calculated by the visible-parameter and not by the effective number of list-items.

    Thx in advance and greets, Markus

  • this blog is about jCarousel Lite and you describe the all the points and feature of it.now it is easy to install jCarousel Lite and get work because you tell the steps how to install it.

  • JC

    I’d like to be able to load thumbnails into the scroller on the fly using ASP… I am doing that now and setting the Height=”125″ and hoping the width would load proportionally for each image. The problem is that it is using the narrowest width for all of the images. With mixed landscape and portrait photos this is not working.
    I’ve tried both

    $(window).load(function() {
    and
    $(function() {
    to load it thinking that had something to do with it, but no luck… any ideas or examples of code that did work for multiple sizes without specifying each height and width?

  • I have a problem with the hover with this one.. when the first 3 news are are hovered, its working fyn but when the next batch is displayed and is hovered it will not change its background color.

  • Steve

    Having a problem with jCarousel Lite inside of Thickbox (iframe content)… http://jquery.com/demo/thickbox/ Seems ok in Safari and Chrome, but in IE and Firefox, the images do not show.

  • hey, thanks for a nice work BTW!

    I have some problems displaying this script in “google chrome” browser.

    Could you check it out and provide the fix please.

  • Umair

    Do it work with jQuery 1.4?

    I m doing almost same coding as i found in view-source of front page / demos, but not working for me, do it needs older version of jquery?

    I m using firefox with latest available jquery

  • Suggested patch: On line 242 there is a js object with css properties. Unfortunately ‘float’ is a reserved word, so js parsers/compressors die when they get to this line.

  • sunil

    Hi,
    can anyone tell me how to dynamically set start position value of jcarousel?

  • Hi Ganesh,

    I’ve modified the code so that you can include a left offset for fine tuning the positioning. I did this because I needed to centre my items relative to an absolutely positioned box that sits above everything.

    It’s not hard-coded, so you can call it inside the options as “leftOffset”. It works from the start, not just after the first animation, and it doesn’t jump in circular mode.

    I thought you might like to see the code and perhaps include it in future versions, also as I’m not a jQuery developer I would imagine there might be errors in scenarios different to mine, so rather than redistribute myself I wanted to send it to you so that you can make sure it works properly.

    If you drop me an email I’ll reply and include the code, to see all instances of lines that I’ve edited search for #LEFTOFFSET. I’ll remind you of this in the email too.

    Jamie Goodwin
    cjgoodwin@gmx.com

  • Hello,

    First thanks for sharing your code.

    Then, I am having a problem with the carousel: when I go on this page (http://dev.eamobileclub.com/m/android3/Carousel.aspx) and press refresh on my HTC Dream, the images disappear. If I go on another page and back to the carousel, the images are back displayed.

    Have you ever encountered this problem?

    Thanks for ur help.

    J

  • Tiziano

    Hi Ganesh,
    Thanks for sharing your code, I’m using your plug in and it works fine. Although I encounter an issue when having in the same list vertical and horizontal images.
    If the first image of the list is vertical then it will fit properly and if any following image is horizontal the image appears cropped.
    Hopefully I just happened to make some mistake while using it.

    Thanks for your help.

    Code:

    $(document).ready(function(){

    $(“.carosello”).jCarouselLite({
    btnNext: “.next”,
    btnPrev: “.prev”,
    visible: 1,
    speed: 200,
    circular: false,
    start: 4
    });
    $(“.carosello”).hide();

    $(‘.view td’).click(function(e) {
    $(‘.carosello’).show();
    $(‘.next’).css({‘display’: ‘block’});
    $(‘.prev’).css({‘display’: ‘block’});
    });
    });

    HTML:
    ——————

  • I am having a problem with the vertical version of the carousel. I am just scrolling text using next and prev buttons. However, in IE7 and IE6 when it scrolls it its off a few pixels and as you scroll more it gets worse because its off. It doesn’t seem to be moving to top position correctly. I also see this problem on your vertical demo page in IE6 and IE7. http://www.gmarwaha.com/jquery/jcarousellite/index.php#demo.
    Any help will be greatly apprecaited.

  • Joen

    Hi,

    Lovely script you have here. I have one question which I hope will be easily answered.

    I want to build a carousel slideshow, which can expand in size by the click of a button. So far, using jQuery, I’ve managed to build just such an expand button. The problem is, the “next” and “previous” buttons still only slide the distance as was defined when the carousel was first initialized. Obviously, these need to slide a longer distance, now that the width is wider.

    So essentially what I need, is information as to how I can change the distance the “next” and “previous” buttons slide, after the carousel has first been initialized.

    If you’re able to help me with this, I’ll buy you a couple of beers through a paypal donation.

  • Dick

    Hi,

    I have a carousel where the user can add and delete images. Adding and Deleting works fine except when you delete until the one before the last one: I expect that, after deleting it, the last one is shown but it isn’t (although it is in the HTML source).

    Is this a bug?
    Kind regards,
    Dick

  • Dick

    In addition to my previous post:
    This problem does not occur if you set “circular: false” in the configuration.
    Dick

  • Fantastic Script.

    Is it possible to make it continuously scroll when I hold the next/prev button down?

    Cheers,
    D

  • Hello! I’m doing something wrong here, I’m sure of it.

    My problem is that the script doesn’t seem to be properly keeping track of its position, particularly when it should wrap around.

    My code is below. I’m using 7 items, 4 visible at a time and advancing by 4. Naturally it works fine if this is 8, but with seven the next time I hit scroll it resets. Here is the pattern I get:

    1234
    5671

    THEN on the next tap it messes up and abruptly changes the pattern to 1234 and scrolls from there to 4567. Is this an error in the script?

    […. item ….]
    […. item ….]
    […. item ….]
    […. item ….]
    […. item ….]
    […. item ….]
    […. item ….]

  • Ram

    Thanx for the post. This is very helpful.

    I was wondering if any scroll bar that is tied up with the carousel can be displayed under the images. Just to give an option for user to both click or slide.
    Please give some hints if anyone have an idea.

    Thanks in advance

  • Hello,
    I saw this plugin in this site ( http://www.gabfirethemes.com/demos/transcript/ )and requested to know what it was, and the author directed me to this blog.
    What I want to ask if its possible to have the carousel go front and back, as long as the person is on the same page.

    Thanks for the great job though

  • RobG

    Wonderful script!

    But I’ve run into a problem and was wondering if you might have a suggestion. I have a circular carousel that is 5 elements wide and scrolls 5 elements at a time (circular:true,scroll:5,visible:5) and I’m using btnPrev and btnNext. It works great if the number of items is divisible by 5 but when I have an odd number, 9 for example, scrolling gets confused when trying to wrap around and moves the wrong number of elements (forward scrolling at least, I can’t remember backward scrolling behavior). If you can’t reproduce or don’t have a solution that’s cool – I’ll be back at work in a few days and will work on a fix. (I’m using 1.0.1)

    Thanks!

    RobG

  • Martin

    Hi, great work!
    I just wonder if it is possible to call the Go(to) method from outside.
    ex( $(“.carousel”).jcarouselLight.go(5) )

    I need to trigger the carousel to go to a specific position. The btnGo-option could work, but not for me, since the controls that has the css-class .1 .2 etc is not populated on the page when the jcarouselLight is initialized. They are created with JQuery.

    What I want is to be able to add a button with JQuery, after the jCarousel has been initialized, that can trigger the carousel to go to a specific position.

    I really hope someone can help me with this!

  • Dougle

    Hey, love this plugin, we use it alot at work.

    Can i suggest that when you clone in the prepend and append calls you pass in a true param, this clones any custom events the user may have attached aswell.

    e.g. ul.prepend(tLi.slice(tl-v-1+1).clone(true))

  • john n

    @Steve regarding issue with firefox and jcarousel in an iframe(with thickbox).

    It wasnt working for me, firefox seems to be having some issue getting the offsetWidth and offsetHeight in an iframe. I replaced the content of the two functions width(el) and height(el) in jcarousel to get the style parameter. Its a horrible hack but it worked in my case, can see issue if your padding or anything.

    So width(el) became:

    var w = parseInt((el[0].style.width).replace(/px,*\)*/g,””));
    return w + css(el, ‘marginLeft’) + css(el, ‘marginRight’);

    Theres bound to be a far better way to get around or fix the issue, but it’ll do for now.. ๐Ÿ™‚

  • Thomas

    Validation:

    Your preview code of the next/previous-buttons are not validating. To fix this, change <> to ยซ and ยป (CTRL + 0711 and CTRL + 1087)

  • I am trying to make this display images randomly but am unsure how to add the math.random code. Can you help? Thank You!

  • Georgiy

    Thanks for plugin! good and light! Thanks a lot!
    but…..
    1.why left button onload doesn’t have class .disabled
    2. And when i add in config scroll:’2′ then gallery scroll for two images, as i wrote, but only once!

  • Uwe

    Hi Ganesh,
    thanks a lot for this easy to install script. Iโ€™m a javascript beginner and for this I love it. But one wish I still have: I would like to highlight (for example with a frame or a variation of the inserted photo) the clicked ul item. Do you have an idea for this? Thanks in advance for your help and kind regards from Germany. Uwe

  • Hi!

    The plugin works great on FF, Safari, Opera, Chrome, IE8,,, but on IE7 it adds extra pixels on the top/bottom on a vertical list of items. So each time the scroll activates and stops, the layout shifts those extra pixels -they add up- and the layout gradually starts to look wrong…

    You can checkout what I am talking about on the following link: http://www.sevime.com

    Do you know a way to fix this problem?

    Best regards!
    Alejandro

  • Would it be possible to limit the depth of list items that the script is looking for? I’m using this as a content slider and typical ‘share’ widgets that work with multiple networks use nested lists to display the various social bookmarks. The script sees these and screws up the carousel. Removing the share code makes it all work fine again.

    Maybe something like only looking for the first list?

  • Hello, I hope the question has not be answered before.
    I’m using jCarouselLite on my future website, and displaying many pictures of various sizes. Some can be 80px large, and some other 300px large. The problem is that all the LI’s are forced to a fixed-width, whereas I’d like to have them just fit the content. How could I get this behaviour?
    Thank you for all the great work !

  • AnubisibunA

    using jQuery 1.4.2 and packed jCarousel_Lite = no IE browser version (not tried 9 beta yet) would display the carousel.

    Using default settings, but set to autoscroll. Anyway, if anyone else has the same issue… I just threw on some conditional comments to show IE users static pictures.

    carousel div and images go here for cool people who use cool browsers


    stupid IE browsers see this

    NOTE: using does NOT work to show in every browser BUT IE, you have to take out the —

  • AnubisibunA

    dangit… forgot to use ascii

    <![if !IE]>
    carousel div and images go here for cool people who use cool browsers
    <![endif]>

    <––![if IE]>
    stupid IE browsers see this
    <![endif]––>

    NOTE: using <––![if !IE]> does NOT work to show in every browser BUT IE, you have to take out the ––

  • Wes Pomeroy

    I’m a big fan of this plugin and have used it extensively, but I feel like I’m taking crazy pills with this issue I’m having. The ‘left’ button switches the slides wihtout a problem. But my ‘right’ button causes everything to freak out. Looking at the style/positioning code being applied to the containing my slide, the match is being calculated all wrong.

    I have a very simple straight-forward setup. My slide HTML and corresponding CSS is this:


    #promo_spot {
    position: relative;
    float: left;
    margin-left: 20px;
    z-index: 1
    width: 970px;
    height: 431px;
    }

    My ‘controls’ HTML and CSS is this:

    #promo_controls {
    position: absolute;
    z-index: 5;
    right: 16px;
    top: 40px;
    width: 180px;
    height: 35px;
    }

    And my JS code to invoke everything is:

    $(“#promo_spot”).jCarouselLite({
    btnNext: “#right_button”,
    btnPrev: “#left_button”,
    visible: “1”,
    circular: true
    });

    What the heck am I missing?