jsor / jcarousel

Riding carousels with jQuery.
https://sorgalla.com/jcarousel/
MIT License
2k stars 734 forks source link

Error when set start position #22

Closed pracj3am closed 13 years ago

pracj3am commented 14 years ago

I'm gettig error "Error: jCarousel: No width/height set for items...", when I set start index > 1 (no problem for start = 1) in this example: http:doubleslash albion.dev.intya dot cz/jcarousel-bug.html (i.e. when it is impossible to scroll start item to the left margin of the carousel).

I expect that in this case carousel should scroll to the left as much as possible even if the start item would not be on the outermost left.

I also found out, that error magically disappears if i set margin to items. But for start=4, the item "Two" is on the start position and the item "Four" stays partially hidden.

Tested in FF 3.5.11

jsor commented 14 years ago

This is a common problem. The point is, that there is no width defined for the items and because of that, jcarousel isn't able to get the actual widths to do required calculations. The only solution right now is to explicitly define a width for the items.

pracj3am commented 14 years ago

But it is strange, that it works if start = 1 or if a margin of items is set to non-zero value. Problems is that the width of a item depends on its content. It would be useful if the width could be measured it in itemFallbackDimension using jQuery's width(), but the fallback would have to have the item as a parameter.

pracj3am commented 14 years ago

I have explicitly defined width of the items using $('.jcarousel').children().width(function(){ return $(this).children().width(); }); (before jcarousel is initialized) but nothing changed at all. The problem is still same as I described in original report.

jsor commented 14 years ago

Try to add the following css:

.jcarousel-skin-intya .jcarousel-item-placeholder {
    width: 100px;
}

I expect that in this case carousel should scroll to the left as much as possible even if the start item would not be on the outermost left.

You can consider this as a "bug". jCarousel sees an item as visible also if its only partially visible. I will add a patch to force an item being completely visible if its defined as the start item.

jsor commented 13 years ago

This has been fixed in http://github.com/jsor/jcarousel/commit/9ff64d5ac2fc47f243a83a54815acb11d30c54f9