jCarousel Lite – A jQuery plugin August 9th, 2007

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. If you like interesting effects, include the Easing plugin as well (Optional). 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/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"><<</button>
<button class="next">>></button>
<div class="anyClass">
    <ul>
        <li><img src="someimage" alt="" width="100" height="100" ></li>
        <li><img src="someimage" alt="" width="100" height="100" ></li>
        <li><img src="someimage" alt="" width="100" height="100" ></li>
        <li><img src="someimage" alt="" width="100" height="100" ></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() {
    $(".anyClass").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev"
    });
});

If you have any comments/suggestions/requests, feel free to drop in a comment or you can find me lurking around the jquery mailing list.

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.

942 Responses to “jCarousel Lite – A jQuery plugin”

« 15 6 7 8 9 10 11 12 13 14 1519 » Show All

  1. 451. pvf on June 15th, 2009 at 10:09 pm

    Hi Ganeshji,

    thanks for the fast response!

    would you mind pointing me in the right direction for this to be coded?
    i am familiar with jquery but not an expert! any help would be appreciated.

    i was thinking of storing the clicks using a .click(function)
    like:
    $(‘li a.carouselImg’).click(function(){
    //store values here
    })

    but im not 100% sure how to approach it….

    thanks,
    pvf

  2. 452. Ganeshji Marwaha on June 16th, 2009 at 4:29 am

    @Tim #450: No, the way the plugin works atleast right now, it is not possible to eliminate the pausing during auto scroll. I myself am looking to change that behavior for one of my clients. So, when i succeed, i will keep this blog updated.

    At present the plugin assumes that all items are of equal height and width. You know typically carousel items are like that. Just place your largest item in the front of the carousel so that all carousel item gets the maximum width. This should solve your problem temporarily

  3. 453. Till on June 16th, 2009 at 10:42 am

    Hey Ganeshji,

    thank you for fast answering.
    Yet I didn´t try your solution, but found another one:

    I´ve used the callback function:

    function initClicker() {
    $(‘.Something’).click(
    // and… Action!
    )
    }

    $(‘.exampleClass’).jCarouselLite({
    afterEnd: function() {
    initClicker();
    }
    });

    and it works. Perhaps its a bit redundant, but… yes.

    Nevertheless, thanx a lot for the plugin und fast answering.

    Greetings from (today) sunny Berlin,
    - Till -

  4. 454. Ganeshji Marwaha on June 16th, 2009 at 11:29 am

    @Till #453: Congrats to get it working. But remember, jquery’s click handler keeps getting added everytime you bind a click event. So, in your case, the event handler will get bound multiple times and will get triggered multiple times. Careful…

  5. 455. darsane on June 16th, 2009 at 4:51 pm

    Thank you for information.

  6. 456. Ctrl + Key Combination - Simple Jquery Plugin | Ganesh on June 16th, 2009 at 8:58 pm

    [...] I had to part with my bandwidth for all other features this plugin offered. Like my famous jCarouselLite plugin, I like my javascript code kept to the minimum. So, I decided and wrote a short yet sweet [...]

  7. 457. Bruce Gilbert on June 16th, 2009 at 9:38 pm

    Hi,

    thanks for this tute. I have the navigation on this page:

    http://www.inspired-evolution.com/Portfolio.php

    the functionality works but not the links. Do you know why this might be?

  8. 458. Ganeshji Marwaha on June 17th, 2009 at 8:08 am

    @Bruce Gilbert: You should remove the “return false;” statement that you are binding for the click event. This will solve your problem. By the way, you have posted on the wrong blog entry. This entry is for jCarouselLite.

  9. 459. ph on June 18th, 2009 at 9:34 am

    This is really a great plugin, especially for sleek lightweight animations. Thanks a bunch!

    However, I’m sorry to bother you with a small problem of mine – any help would be much appreciated:
    I’m experimenting with a mixed content setup (visible: 1, circular: true) and experiencing some weird behavior with the prev button.
    Cycling forward through my 3 test works like a charm (1>2>3>1>2>3>…), however, while going backwards no.3 is always skipped: 1<2<12>3<2<1<2<1<2<1… When test- no1 is active and the prev button is clicked, no2 is shown instead of no3. I’m guessing it could have something to do with weird CSS height problems, but that’s just that: a guess.

    My html is a bit nested, basically it’s a

    texttext

    Any hint as to if you’ve had similar problems in the past or where the problem could derive from would be much apreciated. And apart from that – thanks again for your great plugin :)

  10. 460. ph on June 18th, 2009 at 9:37 am

    sry, html got stripped :)
    next try

    text text

  11. 461. Ganeshji Marwaha on June 18th, 2009 at 9:53 am

    @ph – try putting your html inside “pre” tag

  12. 462. Ganeshji Marwaha on June 18th, 2009 at 9:57 am

    @ph: Instead of pasting your HTML code here, if you can provide a link to a page where i can see this behaviour in action, I could probably help you better.

  13. 463. ph on June 18th, 2009 at 10:04 am


    Some more testing revealed that after restricting the width: of the containing div (anyclass)to about 500px and deliberately clicking the prev-button slowly, the problem does not occur every time. as i dont expect visitors on my client’s site to click the prev button too fast, i guess the problem isn’t severe.

  14. 464. Ganeshji Marwaha on June 18th, 2009 at 10:27 am

    @ph: Glad the problem isn’t severe. Still you shouldn’t be facing that problem at all. The Project Page itself contains an example of {visible: 1, circular: true} and I am unable to notice a problem.

  15. 465. ph on June 18th, 2009 at 10:43 am

    thanks for taking your time to solve my problem, I’m currently doing some further testing. Unfortunately, I can’t post links to the live version publicly (see ->twitter on how to find another way perhaps :) . Probably other css from the rest of my site is interfering with the carousel, however there is no other js/jquery used on the site. the problem occurs afaik in ff3.5, opera b10 and ie8 (winxp).

  16. 466. DonD on June 19th, 2009 at 1:41 am

    total Newb question…. Where does this go? Step #3:

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

  17. 467. Ganeshji Marwaha on June 19th, 2009 at 11:11 am

    @DonD #466: That goes inside a “script” tag within the “head” tag of your HTML page.

  18. 468. kevinsturf on June 19th, 2009 at 11:26 am

    hey there im having an issue with this.i set the visibility to 1 and two displays, one where i want it and the other right below it.in the css, i set overflow to hidden but that didnt work. now when is et the vidibility to 0 the one i want shows up great but when scrolling through and it reaches the end, it shows nothing but the carousel container bg and i have to hit the next button once again to view more.

    also if i set the visibilty to 1, it works fine but the extra image at bottom.

  19. 469. kevinsturf on June 19th, 2009 at 11:32 am
  20. 470. Ganeshji Marwaha on June 19th, 2009 at 12:50 pm

    @kevinsturf #469: I checked it out. I guess there is some issue with “vertical mode and visible: 1″. But, it works flawlessly in horizontal mode. It could take some time for me to fix this issue. So, kindly work with horizontal mode until then. Thanks.

  21. 471. Thomas René Sidor on June 19th, 2009 at 1:21 pm

    Hey. Thanks for a great and lightweight carousel. I’m having a little trouble with it though; when I scroll right all the items animate out of view very quickly. If I scroll right again – they quickly appear and animate away again. If I scroll left it works fine – also with scrolling right afterward. Any suggestions?

  22. 472. Brian Vallelunga on June 19th, 2009 at 5:20 pm

    This is a great plugin. I’m using it now on a new project. I’ve also needed to implement a tabbing scenario where the ‘go’ button that corresponds to the current element needs to be highlighted.

    I’ve worked it out myself using class names and the beforeStart and afterEnd callbacks, but it’s messy and doesn’t scale well.

    Perhaps you could provide the original indices of the visible elements in the beforeStart and afterEnd callbacks along with the items themselves. This would let us match up the current item with a current button (or buttons).

  23. 473. Brian Vallelunga on June 19th, 2009 at 10:09 pm

    I have a suggested change to the library for you. I changed lines 228 and 236 to use direct child selectors for the ul and li elements. This allows putting in content that contains unordered lists itself.

  24. 474. Mark W on June 20th, 2009 at 2:28 pm

    Ganeshji, I saw your comment about the height being calculated on the first li only. Your statement is you don’t know a use case for variable heights. I was looking at using your plugin to do a carousel of my latest blog posts on my site. The problem is that the amount of text that is quoted becomes a variable on how much is shown, so, the first one may be a little short, the second one longer and cut off.

    Any more thought on looking into calculating the height of all of the LI first?

    Thanks, Mark

  25. 475. Marios on June 22nd, 2009 at 9:07 am

    How do i simulate the next,prev actions on mouse hover

  26. 476. Mark W on June 23rd, 2009 at 9:51 pm

    So, I was looking at a way to deal with the variable height on items where the first one is not always the longest (per my message above). Here’s the solution I came up with:

    Note: For those who are reading this, if you don’t know what you’re doing, probably not a good idea to try on your only copy.

    In the jcarousellite_1.0.1.min.js file:

    Change this code:
    f.css({width:f.width(),height:f.height()});

    to:
    f.css({width:f.width(),height:g});

    Change:
    function css(a,b){return parseInt($.css(a[0],b))||0};

    to:
    function css(a,b){ return parseInt($.css(a,b))||0 };

    and change:
    function height(a){return a[0].offsetHeight+css(a,’marginTop’)+css(a,’marginBottom’)}

    to:
    function height(a){
    var z = 0;
    for (y=0;y z) z = x;
    }
    return z;
    }

    Because I only care about a variable vertical length, this only works for that, doesn’t take into account variable widths.

    I’m not saying this is the best solution or the most efficient one, but for those who are looking for this, there you go…I haven’t testing it out extensively at this point.

  27. 477. Mark W on June 23rd, 2009 at 9:53 pm

    That last function got cut, let’s see:

    for (y=0;y < a.length;y++) {
    x = a[y].offsetHeight+css(a[y],’marginTop’)+css(a[y],’marginBottom’);
    if (x > z) z = x;
    }

    In case they come through, replace < with the less then sign, and > with the greater then sign.

  28. 478. Barbod on June 24th, 2009 at 6:11 am

    Hi Ganeshji,

    thanks for the fast response!

    i am familiar with jquery but not an expert! any help would be appreciated.

    i use ASP.NET3.5 and when i used master-page and load child-page(contain jCarousel control) in tag :

    test

    Child- Page :

    <<
    >>

     Test0 
     Test1 
     Test2 
     Test3 
     Test4 
     Test5 
     Test6 
     Test7 
     Test8 
     Test9 

    $(“.container .anyClass”).jCarouselLite({
    btnNext: “.container .next”,
    btnPrev: “.container .prev”
    });

    it didn’t show any content!?!?!? just show buttons !?!?!?!
    how can i solve this problem ???

    please HELP me , so thanks

  29. 479. Barbod on June 24th, 2009 at 6:16 am

    hi again , i used tag TABLE in master page …

    please HELP me , so thanks

  30. 480. Ganeshji Marwaha on June 24th, 2009 at 7:51 am

    @Thomas #471: Please direct me to a link where I can take a look at the problem.
     
    @Brian #472: Nice Idea. I will get to implementing it as soon as I can squeeze out some time. Thanks for the suggestion and I am glad you got it working anyways.
     
    @Brian #473: Thanks. Can you kindly email me the modified version at ganeshread [at] gmail dawt calm. I will try and incorporte it into the next release.
     
    @Mark W #474: I understand you requirement. But at the same time, wouldn’t you fix some height for the carousel elements by default. Obviously you don’t want your blog post carousel to grow bigger than a particular height. isnt it? If that is the case you can fix the height of the li’s thus making the use-case work. Even otherwise i get your point. I will try to implement it as soon as i can squeeze out some more time. Thanks.
     
    @Marios #475: Right now the carousel allows only click events for “next” and “prev”. Just browsing through the code and changing a few lines where the buttons are bound to “click” events to “hover” events should solve your problem.

  31. 481. Ganeshji Marwaha on June 24th, 2009 at 7:55 am

    @Mark W #477: Nice work. Thanks for helping others in the forum with your custom modification. Programmers like you who share are those who make open source tick.

    @Barbod #479: The information given is not enough for me to know what the problem could be. Kindly direct me to a page where I can see the problem live. That way it is very easy for me to spot the problem. Thanks.

  32. 482. Jon Winer on June 24th, 2009 at 7:24 pm

    I was able to setup a sample page using this plugin and it worked great, but now I am attempting to integrate this into an existing site and I am getting the following error in the height method:

    el[0] is undefined

    Not sure what is causing this. Any help much appreciated. thanks.

  33. 483. Jon Winer on June 24th, 2009 at 8:51 pm

    Prior post (482) was resolved. Issue was caused by another javascript error present on the page.

  34. 484. Jon Winer on June 24th, 2009 at 10:34 pm

    I am attempting to use the scrollable settings, but whenever I set one of the vertical settings other than ‘vertical: true,’, it no longer scrolls. It also appears to not scroll when ‘circular: true’ is set. The other issue I am having is that the btnNext and btnPrev seem to scroll the list in the same direction when vertical or circular is not set.

    Thanks for your help.

    Jon

    function enableListItemScroll() {
    $(“.vertical .listItemScroll”).jCarouselLite({
    btnNext: “.vertical .listItemScrollDown”,
    btnPrev: “.vertical .listItemScrollUp”,
    vertical: true,
    speed: 400,
    scroll: 1,
    start: 0,
    visible: 6,
    circular: false
    });
    }

  35. 485. orlando on June 26th, 2009 at 7:52 pm

    Help!!!! A little background about myself I am a designer (please no smirking) and I placed your wonderful plugin on the website but it blows up in IE (what a surprise). I am designing on a mac but I tested it on a PC as well. It also doesn’t work on Safari. Please help me I have been fighting over this for over a week and I have to launch asap. Your help will be more than appreciated. Remember I am not a developer but I have to unfortunately wear many hats in this firm so please be detailed in your explanation so I can figure it out. Thank you so much again.

  36. 486. orlando on June 26th, 2009 at 7:54 pm

    p.s
    It works great in Firefox so there is hope for me yet. The website is jumbamediagroup.com/test.

    Thanks

  37. 487. Anonymous on June 26th, 2009 at 8:17 pm

    Dude, you need to expose a contact form so we can get a hold of you for questions. This thread is getting way too long.

    I wanted to know if you have an example of loading via URL with AJAX. So far I see example of loading from an XML file, but we are trying or want to use your carousel to lazy load. So for example, you click the next button, it dynamically calls our url, we get back XML, I will parse that with jQuery and so dynamically fill the pictures as needed. We don’t want to fill all our images on page load, that would bring down our server since we have millions of users hitting the site.

    Any way to do this? jQuery ajax request to url (hits a handler and handler sends back XML to be parsed) and then able to take response and show those pictures in your carousel this way?

    Deferred loading via url is what I’m after here.

  38. 488. Anonymous on June 26th, 2009 at 8:19 pm

    You need a support forum for this plug-in!

  39. 489. Ganeshji Marwaha on June 27th, 2009 at 8:21 am

    @orlando #485, #486: Please provide the height and width for all your carousel elements in css specifically. That should solve your problem. If it doesn’t let me know.

    @Anonymous #487, #488: jCarouselLite is specifically built for very light weight use-cases. If Ajax based features are included into this plugin, it will no more remain jCarouselLite. There is another plugin called jCarousel that offers all the features you are looking for. Although jCarouselLite has a plethora of features, all of them have been added without introducing more KBs in. Thanks for trying jCarouselLite though.

  40. 490. Jonathan on June 27th, 2009 at 5:41 pm

    Hi, and thanks for this great plugin! I have a question, but couldn’t find the answer through google. I want to stop an automatic circular carousel. I tried doing something like this :

    $(“#text-viewport”).jCarouselLite({

    auto:null

    });

    but it doesn’t work as I thought it might…
    Any help ?

  41. 491. Snuggie on June 28th, 2009 at 5:00 pm

    I am using this theme for my site which is in maintenance mode – but here’s the developer theme demo – http://www.press75.com/the-folio-elements-wordpress-theme/

    When you click thru 3 times, the windows (light box/facebox) stop working. I don’t know if you can help me with that or not, but the developer is not helping us to fix the issue. It even does the same thing on his demo site. Is there a fix that someone who isn’t a programmer can fix?

  42. 492. gnysek on June 29th, 2009 at 3:44 pm

    When I’m using auto scroll, after pressing “prev/next” button time of next scrolling is not extended. For example: autoscroll time is 2 seconds, and I pressed next button five times, so next item will slide automatically just in a half of second later, not after 2 seconds.

    Sorry for my horrible English…

  43. 493. gnysek on June 29th, 2009 at 4:11 pm

    Ok, I fixed it. I added new variable myinterval, and added in function go(to):

    if(o.auto)
    {
    clearInterval(myinterval);
    myinterval = setInterval(function() {
    go(curr+o.scroll);
    }, o.auto+o.speed);
    }

    also changed to “myinterval = setInterval several” lines before function go(to) (code looks similiar than this one i posted above).

  44. 494. Ganeshji Marwaha on June 30th, 2009 at 3:37 am

    @gynsek #492, #493: Good work. Glad you fixed it and got it working.

  45. 495. Faaiz on June 30th, 2009 at 6:09 am

    Hi,
    Am using jcarousellite view to display Images in nodes in drupal based site. My great issue is, the default visible set on jcarousellite_add_view_js() is visible = 3, but i want to customize it that it would be visible = 1 for home page and visible = 3 for navigation links. Where could i customize it. pl help me immediately.

  46. 496. Ganeshji Marwaha on June 30th, 2009 at 6:29 am

    @Faaiz #495: I have no idea how to use jCarouselLite in Drupal. So, I cannot be of much help there. But, as far as the plugin itself is concerned, you have to just set “visible:3″ as its option or “visible:1″ as its option to achieve what you want. Hope that helps.

  47. 497. Ben on July 1st, 2009 at 4:32 pm

    Hi

    Great plugin. Definitely the best Carousel I’ve found – and I’ve tried half a dozen of them in the last couple of days.

    Is there a way of resetting the carousel? Or even better – sending it to a certain index in the carousel?

    My implementation changes the contents of the carousel through user input – this works fine, but it would work better if I could send the caroussel back to its initial position.

    Cheers
    Ben

  48. 498. Thibault on July 1st, 2009 at 6:10 pm

    Hi thanks for this wonderful piece of work.
    I’ve been trying to add a right margin on the picture but I can’t make it work..
    Could you help me please.

    I’m using the Default Configuration.

  49. 499. jeff on July 1st, 2009 at 8:59 pm

    Hi Ganeshji,

    Thanks for the great carousel. I am a total nube when it comes to Jquery or javascript. The best i can do is copy and paste your code and hope for the best. I am having problems with the jCarousel Lite at the above address under Media / previous messages. the pictures in the carousel dont load on the first time that you access the page. But if you hit the back button and then the forward button. the carousel appears on the page the way its suppose to. I only know html (with much dreamweaver help)so please dont laugh when you look at my code. lol

  50. 500. Ganeshji Marwaha on July 2nd, 2009 at 6:41 pm

    @Jeff #499: I checked out your webpage and the carousel seems to work fine. You probably have fixed it in the meantime, or I am missing something here. Which browser were you facing this problem in?

    @Thibault #498: The information you have given is too less to work with. Can you kindly direct me to link where I can see it in action.

    @Ben #497: I see your point. I myself recently came across the need to send the carousel to a given index but since that need passed away, I forgot about it. Most probably I will get around to implementing that feature pretty soon. But I can’t promise you a date. In the meantime if you get around to fixing it, please keep me in the loop so that I can update jCarouselLite with that new feature.

« 15 6 7 8 9 10 11 12 13 14 1519 » Show All

Leave a Reply