Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Owl Carohausel onChange仅在页面更改时触发_Javascript_Jquery_Owl Carousel - Fatal编程技术网

Javascript Owl Carohausel onChange仅在页面更改时触发

Javascript Owl Carohausel onChange仅在页面更改时触发,javascript,jquery,owl-carousel,Javascript,Jquery,Owl Carousel,我正在使用OWLCarousel2,每页设置3个项目。我希望在幻灯片事件发生时选择每一个项目,因为我模糊了第一个和第二个项目,并使第二个项目可见 我使用这段jQuery代码来实现这一点: $("#service-slider .active:eq(1)").addClass("myActive"); 这就是我启动猫头鹰旋转木马的方式: $("#service-slider").owlCarousel({ loop: true, margin: 10, nav: true

我正在使用OWLCarousel2,每页设置3个项目。我希望在幻灯片事件发生时选择每一个项目,因为我模糊了第一个和第二个项目,并使第二个项目可见

我使用这段jQuery代码来实现这一点:

$("#service-slider .active:eq(1)").addClass("myActive");
这就是我启动猫头鹰旋转木马的方式:

$("#service-slider").owlCarousel({
    loop: true,
    margin: 10,
    nav: true,
    dots: false,
    autoplay: true,
    autoplayTimeout: 5000,
    autoplayHoverPause: false,
    smartSpeed: 1500,
    onChange: activeSelect(),
    onDrag: activeSelect(),
    onTranslate: activeSelect(),
    responsive: {
        0: {
            items: 1
        },
        600: {
            items: 1
        },
        1000: {
            items: 3
        }
    }
});

$("#service-slider .active:eq(1)").addClass("myActive");

function activeSelect() {
    $("#service-slider .active").removeClass("myActive");
    $("#service-slider .active:eq(1)").addClass("myActive");
}

var owl = $('#service-slider');
owl.owlCarousel();
owl.on('next.owl.carousel', function (event) {
    $("#service-slider .active").removeClass("myActive");
    $("#service-slider .active:eq(1)").addClass("myActive");
});
owl.on('prev.owl.carousel', function (event) {
    $("#service-slider .active").removeClass("myActive");
    $("#service-slider .active:eq(1)").addClass("myActive");
});
它第一次工作正常,但当项目转换时,它不工作;仅在整个页面更改时工作


这里有一个问题:

用户7290573找到了解决方案。您可以使用猫头鹰旋转木马的中心选项来实现我想要的。他的小提琴可以在这里找到:


使用
center:true
选项怎么样?事实上,这很好用。我想我已经把它复杂化了。
$("#service-slider").owlCarousel({
    loop: true,
    margin: 10,
    nav: true,
    dots: false,
    center: true,
    autoplay: true,
    autoplayTimeout: 5000,
    autoplayHoverPause: false,
    smartSpeed: 1500,
    responsive: {
        0: {
            items: 3
        },
        600: {
            items: 3
        },
        1000: {
            items: 3
        }
    }
});