Owlcarousel2: Owl Fails with Loop Set to True & Only 1 Item + Feature request

Created on 13 Oct 2016  路  3Comments  路  Source: OwlCarousel2/OwlCarousel2

Hi,

I am using 2.0.0-beta.2.4.

When loop:true and there is only one item it fails with uncaught TypeError

Uncaught TypeError: Cannot read property 'clone' of undefined

Upon inspecting the elements, Owl is trying to add 2 more items with cloned class

I have followed the issue reported before
http://stackoverflow.com/questions/32311300/owl-carousel-2-not-work-with-loop-and-1-items-bug-fixed-now
https://github.com/OwlCarousel2/OwlCarousel2/pull/1028

However its not reflected on the version I have downloaded.

This hack works

owl.carousel.js
line 289

changing from
delta = this.settings.loop ? clones.length - Math.max(this.settings.items * 2, 4) : 0

to
delta = this.settings.loop ? clones.length - Math.max(this.settings.items * 2, 2) : 0

However single item is rolling over like crazy.

Instead it would be desirable to set loop:false when only one item is present.

Thanks!

Most helpful comment

I generally use:
loop: $(this).find('.owl-carousel .item').size() > 1 ? true:false,
as a temp fix on each carousel.

All 3 comments

I generally use:
loop: $(this).find('.owl-carousel .item').size() > 1 ? true:false,
as a temp fix on each carousel.

@vorbe which can be simplified down to just:
loop: $(this).find('.owl-carousel .item').size() > 1

(Sorry about the canned reply.)

You have not added a link to a working live example.

Please add a link to a page where I can verify this error. You can use a service like jsfiddle, plnkr, jsbin or codepen.

And make sure you're using the latest Owl Version! I will close this issue for now, once you provided a working example you can reopen it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SimonHarte picture SimonHarte  路  3Comments

HansGerber picture HansGerber  路  4Comments

shofer4eto picture shofer4eto  路  4Comments

Dipak-Chandran picture Dipak-Chandran  路  3Comments

hopea114y picture hopea114y  路  3Comments