Owlcarousel2: Loop: true and 1 item

Created on 12 Jul 2014  ·  8Comments  ·  Source: OwlCarousel2/OwlCarousel2

This is probably an edge case, but loop break when only 1 item is provided in the carousel.

<div class="carousel">
            <img src="http://lorempixel.com/1903/400/people/1" alt="">
        </div>
    $('.carousel').owlCarousel({
        items: 1,
        autoplay: true,
        loop: true
    });
Uncaught TypeError: Cannot read property 'clone' of undefined owl.carousel.js:299
Owl.Pipe.run owl.carousel.js:299
_.isFunction.e jquery.js:14
Owl.update owl.carousel.js:533
Owl.refresh owl.carousel.js:579
Owl.initialize owl.carousel.js:426
Owl owl.carousel.js:194
(anonymous function) owl.carousel.js:1797
_.extend.each jquery.js:14
_.fn._.each jquery.js:14
$.fn.owlCarousel owl.carousel.js:1795
(anonymous function) (index):350
bug

Most helpful comment

var owl_article = $('.carousel_article').find('.owl-carousel');
var item_amount = parseInt( owl_article.find('.item').length );
var true_false = 0;
if ( item_amount <=1 ) {
true_false = false;
//Например, в слайдере нужно показывать 1 элемент
//если в слайдере 1 элемент, то зацикливать карусель не нужно ---> ставим false
//а также перетаскивание мышью и все остальные нунужные элементы.
}else {
//если на странице больше элементов, чем нужно выводить в первом экране, то ставим true, чтобы зациклить по кругу слайдер.
true_false = true;
}
owl_article.owlCarousel({
items:1,
loop:true_false,
touchDrag:true_false,
mouseDrag:true_false
});

All 8 comments

Would be helpful if you had created a live example with JSbin, JSFiddle etc. See https://github.com/OwlFonk/OwlCarousel2#bug-reports. http://jsfiddle.net/NwDLz/

Confirmed!

Here is a demo with the pull request: http://jsbin.com/purokesu/1/edit.

Hi, sorry for lack of jsfiddle.
I will make sure to add them for future reports.
Great wrk on a solution

Thanks!

var owl_article = $('.carousel_article').find('.owl-carousel');
var item_amount = parseInt( owl_article.find('.item').length );
var true_false = 0;
if ( item_amount <=1 ) {
true_false = false;
//Например, в слайдере нужно показывать 1 элемент
//если в слайдере 1 элемент, то зацикливать карусель не нужно ---> ставим false
//а также перетаскивание мышью и все остальные нунужные элементы.
}else {
//если на странице больше элементов, чем нужно выводить в первом экране, то ставим true, чтобы зациклить по кругу слайдер.
true_false = true;
}
owl_article.owlCarousel({
items:1,
loop:true_false,
touchDrag:true_false,
mouseDrag:true_false
});

I have found that if you enter owl-item rather than "item" you get two "owl-item" for one side as this is automatically added, this can cause this error. Only use class="item"

@themestechnology amazing thanks! item instead of owl-item worked!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hemanthsp picture hemanthsp  ·  3Comments

SimonHarte picture SimonHarte  ·  3Comments

leighfarrell picture leighfarrell  ·  3Comments

mkraha picture mkraha  ·  4Comments

edelworksgithub picture edelworksgithub  ·  4Comments