触发下一页owl carousel 2

时间:2015-06-13 22:34:31

标签: jquery owl-carousel

我正在使用Owl Carousel 2,我有自定义导航按钮,我打算用于next / prev项目和next / prev页面。我正在使用以下内容触发下一项:

var slider = $('.owl-carousel');

$('#nextItem').click(function () {
    slider.trigger('next.owl.carousel');
});

工作正常,但我还需要触发下一页(类似于点的工作方式)。看起来有一个slideBy选项可以用来滑动页面,但这不会有帮助,因为我需要项目和页面导航。

$('#nextPage').click(function () {
    // go to next page
});

3 个答案:

答案 0 :(得分:8)

您可以触发点击点击:

// Go to page 3
$('.owl-dot:nth(2)').trigger('click');

要转到下一页或第一页,如果你在最后一页,你可以这样做:

var $dots = $('.owl-dot');

function goToNextCarouselPage() {    
    var $next = $dots.filter('.active').next();

    if (!$next.length)
        $next = $dots.first();

    $next.trigger('click');
}

$('.something-else').click(function () {
    goToNextCarouselPage();
});

答案 1 :(得分:5)

您可以触发点击下一页(滑块)只添加选项

slideBy: 3 

.....         
responsive:{
                0:{
                    items:1,
                    nav:false
                },
                600:{
                    slideBy: 3,
                    items:3,
                    nav:true
                },
                1000:{
                    slideBy: 3, //Option for trigger next page to click on nav.
                    items:3,
                    nav:true,
                    loop:true
                }
            }
.....

答案 2 :(得分:2)

$('#js-carousel-models').owlCarousel({
    center: true,
    items: 1.5,
    loop:true,
    margin: 0,
    dots: true,
    autoplay: true
});

var owl = $('#js-carousel-models');
owl.owlCarousel();

$('.owl-item').click(function() {        
    if( $(this).next().hasClass('center') ){
        // scroll to prev
        owl.trigger('prev.owl.carousel');
    }
    if( $(this).prev().hasClass('center') ){
        // scroll to next
        owl.trigger('next.owl.carousel');
    }            
})
相关问题