OwlCarousel2 - 添加项目 + 更新轮播 [英] OwlCarousel2 - Add Item + Update Carousel

查看:71
本文介绍了OwlCarousel2 - 添加项目 + 更新轮播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直难以将 Owl Carousel 添加到我们的应用程序,并希望最新的 2.0.0-beta.2.4 版本会更容易,但我无法获得添加项目的基本功能并更新轮播以使其正常工作.

I've been having difficulty adding the Owl Carousel to our app, and was hoping that the latest 2.0.0-beta.2.4 version would be easier, but I am not able to just get the basic feature of adding an item and updating the carousel to work.

我在这里做错了什么吗?

Is there something I am doing wrong here?

这是我使用的代码:

$('#insert').on('click', function () {
    owl.trigger('add.owl.carousel', '<div class=\"item\"><p>D</p></div>').trigger('update.owl.carousel');
});

连同演示:

http://jsfiddle.net/52r9B/11/

文档(http://www.owlcarousel.owlgraphic.com/docs/started-welcome.html) 似乎不包含任何内容 - 除非我遗漏了一些明显的内容.

The documentation (http://www.owlcarousel.owlgraphic.com/docs/started-welcome.html) doesn't seem to include anything - unless I'm missing something obvious.

任何帮助将不胜感激.

推荐答案

自上个月以来,OwlCarousel 2.0 进行了大量重构.所以你用的版本(2.0.0-beta.2.4)已经过时了.

Since the last months OwlCarousel 2.0 is under heavy re-factoring. So the version you have used (2.0.0-beta.2.4) is already outdated.

这是您演示的有效 Codepen.您的第一个错误是您使用事件 API 添加了一个新项目,而没有将参数放入数组中:

Here is a working Codepen of your demo. Your first mistake was that you have used the event API to add a new item without putting the arguments into an array:

// Right
$('.owl-carousel').trigger('add.owl.carousel', [first, second])
// Wrong
$('.owl-carousel').trigger('add.owl.carousel', first, second)

或者你可以使用这样的插件方法:

Alternatively you could use the plugin method like this:

$('.owl-carousel').owlCarousel('method', first, second, third, ...)

主要区别在于事件 API 仅提供所有公共方法的一个子集.

The main difference is that the event API only provides a subset of all public methods.

第二个错误是您试图通过事件 API 调用 update 这是不可能的(见上文).改用 refresh.

The second mistake was that you have tried to call update over the event API which is not possible (see above). Use refresh instead.

要查看最新开发,您需要构建直到下一个预发布 即将推出.但请耐心等待,这仍然是测试版!

To checkout the latest development you need to build it at your own until the next pre-release is coming. But please be patient this is still beta!

这篇关于OwlCarousel2 - 添加项目 + 更新轮播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆