How to setup jCarousel Lite for multi-width images
January 31st, 2010 by
jCarousel Lite is a classic and very light weight jquery plugin.
It’s properties include : orientation (horizontal or vertical), how many images are displayed at a time, various ‘easing’ motion effects and more.
The reason I like it is that of all image carousel plugins for jQuery it is the easiest to tweak, plus – it’s really lightweight.
Most image sliders are built to work well with images that have the same width. The reason is that the container width of each of the images is defined by the width of the first image.

If you want jCarousel Lite to work with images that have different width, you need to do some changes. Let’s see what options we have:
- First and easiest: place the widest image in the gallery in the first position.
- If you don’t wont to change the image order, you can do a small js change (the following change is recommended only if you use jCarousel Lite for a single gallery in your site!):
First, download the uncompressed version of the plugin from the site.
Second, search for “width(el)” (in the version I tested, 1.01, it’s line 134) and change the ’0′ digit inside the parenthesis to the ordinal number number of your widest image, minus 1 (e.g. if your widest image is the third one, put ’2′ instead of the ’0′). - If you don’t want to change the image order and you also prefer not to deal with javascript code, you can simply widen the layout size of the first image in your gallery. That is, without changing the actual visible image size. To do this, in photoshop change the Canvas Size by going to Canvas Size –> Width).
To conclude: I definitely recommend this plugin because it provides some nice features with ease and without burdening the site loading speed. To read more and download the plugin click here.
What about you? do you use this plugin or rather use different ones? how did you manage a to display a slideshow for images with different sizes?

Thank you for this great tip!
I’m trying ton center horizontally narrowest images. I tried with css but I can’t solve the problem. Can you help me ?
Thanks raphael.
Can you show me the problematic page or paste the code?
Hello Omer, thank you for your answer.
Here is the template : (link removed due to invalidity)
@raphael – there is a float:left property of .jcarousel-list li a, .jcarousel-item
It is set in the file http://www.niconeefs.com/wp-content/plugins/carousel-gallery-jquery/carousel-gallery-jquery.css.
Delete the float:left property and see if it works for you
You are briliant, It works now.
Thank you Omer, and have a nice day.
No problem. I’m glad I could help
I load my images dynamically from an uploaded photo list. I do not know the images sizes when my ASP code constructs the code, so the widest photo could be anywhere in the list. When I define the list of photos I set the height to 125px (which most are fixed at) and let the width change proportionally. My problem is sometimes all of the images get resized to be too narrow (it depends what order they get displayed in). Should I be somehow checking the image widths with javascript and then using this value to do what you describe above?
That seems like it might work. I think you should give it a try. If it doesn’t, you can give me the link to your site to take a look.
For now I actually found an easier, but not 100% ideal fix. I surrounded the image with a fixed width DIV and the image shows fine… with extra space around it, but good enough for now.
I’m glad you find a solution, JC.
Seems like a bit of a work around, but I might be giving this a shot since there’s not many jQuery carousels out there that allow different image sizes.
Hello
Are you sure it uses the width of the first image? for my case it has no particular order!!
Quite sure, Mohammad. Unless they updated the code since I wrote this article.
Well, guys, am I right that there will be empty space at the right of each narrow photo?
Hello,
I have tried this fix with the new version. Doesnt seem to work. Do you think you could help me out?
Hi Karla, which of the fixes did you try exactly?
Hi omer nice workaround you got here.
But i have a problem with your solutions here
I try to display text instead of image, and it’s from database, i don’t know which text is the longest of them.
So manually change the width(el) in the javascript won’t work for me.
Any other solution ?
Sorry for my bad english
Thanks
Hi Denny,
Try replacing:
function width(el) {return el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
with:
function width(el) {var widest = null;
el.each(function() {
if (widest == null)
widest = el.index(this);
else{
if ($(this).width() > el[widest].offsetWidth)
widest = el.index(this);
}
});
return el[widest].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
This function will find the widest text block and will use it instead of the first text block.
Hi omer, seems like it’s working fine, i tested on height() function also, it worked, no error, but i feel like it’s a bit slower the and the animation seems like not smooth or maybe it’s just me.
Thanks a lot anyway omer
Denny, it shouldn’t be slower than the original solution. Regarding the smoothness, it is known that this carousels tend to have a bit of flickering on slow movements.
Ok Omer
Thanks for your great solution
there is a simpler solution… at least in the latest version of jcarousel.
in the example file there are 75px wide images. just go into the css file you are using for the skin (“skin.css”) and find every instance of “width:75px” and just remove them. the widths will then scale to the images you insert.
worked for me anyway.
sorry, i wasnt using “lite” just regular jcarousel. so, do what you will with that information.
hello friends this code is working fine for me as a different height. but there are lot of space with less height images. my client doesn’t want this blank spaces near the narrow size pics
so please provide solutions for this blank space.
thanks
I discovery a simple solution for work with this plugin when the images files come from a DB.
In your HTML you put:
<li style="width:px !important”>
<img src="imgfile" />
And in the carousel.js you search for :
li.css({width: li.width(), height: li.height()});
and delete the width value this way:
li.css({height: li.height()});
In the HTML you put the image and the li tag with a dinamic width, and in the js file you delete the value of the li tag.
Works fine this way