简体   繁体   English

猫头鹰轮播addItem问题

[英]Owl Carousel addItem issue

I'm currently using Owl Carousel and populating via AJAX. 我目前正在使用Owl Carousel,并通过AJAX进行填充。 When I use the addItem method Owl Carousel goes to the first item, but I want the carousel to go to the item that was added. 当我使用addItem方法时,Owl Carousel转到第一个项目,但我希望该转盘转到已添加的项目。 So to get that I used jump to, but the problem here is the carousel goes to first and then jumps to added item. 因此,要使用我跳转到的内容,这里的问题是轮播首先转到然后再跳转到添加的项目。 I just need the carousel to go to latest item. 我只需要轮播即可转到最新项目。

i had the same issue so i used lazyLoad : true, 我有同样的问题,所以我用了lazyLoad:true,
I resolved it using this code below: 我使用下面的代码解决了它:

var itemBlock ='<div> slider item </div>'; \\ add your code in ajax

$('#owl-slider').html(itemBlock).trigger('create');

$("#owl-slider").owlCarousel({
        // Most important owl features
        ltr:true,
        items : 5,
        itemsCustom : false,
        itemsDesktop : [1199,8],
        itemsDesktopSmall : [980,5],
        itemsTablet: [768,4],
        itemsTabletSmall: false,
        itemsMobile : [479,2],
        singleItem : false,
        itemsScaleUp : false,

        //Basic Speeds
        slideSpeed : 200,
        paginationSpeed : 800,
        rewindSpeed : 1000,

        //Autoplay
        autoPlay : false,
        stopOnHover : false,

        // Navigation
        navigation : false,
        navigationText : ["prev","next"],
        rewindNav : true,
        scrollPerPage : false,

        //Pagination
        pagination : false,
        paginationNumbers: false,

        // Responsive
        responsive: true,
        responsiveRefreshRate : 200,
        responsiveBaseWidth: window,

        // CSS Styles
        baseClass : "owl-carousel",
        theme : "owl-theme",

        //Lazy load
        lazyLoad : true,
        lazyFollow : true,
        lazyEffect : "fade",

        //Auto height
        autoHeight : false,

        //JSON
        jsonPath : false,
        jsonSuccess : false,

        //Mouse Events
        dragBeforeAnimFinish : true,
        mouseDrag : true,
        touchDrag : true,

        //Transitions
        transitionStyle : false,

        // Other
        addClassActive : false,
        activeClass:true,

        //Callbacks
        beforeUpdate : false,
        afterUpdate : false,
        beforeInit: false,
        afterInit: false,
        beforeMove: false,
        afterMove: false,
        afterAction: false,
        startDragging : false,
        afterLazyLoad : false
    });

var owls = $("#owl-slider").data('owlCarousel'); 
owls.goTo($('.item').length);

By stepping through the execution of addItem() I've noticed that the entire carousel is "destroyed" first then rebuilt with the new item added. 通过逐步执行addItem()我注意到整个圆盘传送带被“破坏”,然后使用添加的新项进行重建。 So for now there is no real solution to your problem. 因此,目前还没有真正解决您的问题的方法。

If you wish to jump to the latest item while keeping the sliding animation (not starting from the first then whoosh to the last), try jumpTo() to the second last item, set a timeout of like 10 milliseconds (will not work if omitted in my case), then call next() . 如果您希望在保持滑动动画的同时跳到最新的项目(不是从第一个开始然后是jumpTo()到最后一个),请尝试将jumpTo()到倒数第二个项目,将超时设置为10毫秒(如果省略,将不起作用)就我而言),然后调用next()

owl.jumpTo(/*second last item index*/);
setTimeout(function() {
  owl.next();
}, 10);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM