【发布时间】:2019-08-16 17:25:09
【问题描述】:
我想在owl.trigger('to.owl.carousel', index)中使用event.item.count的值
加载时,我希望轮播滚动到最后一个可用的项目,如果您有一定数量的项目,这很好,但我的项目列表(即将发生的事件)是动态的并且总是被添加到。我看到您可以在回调事件 fn owl.on('initialize.owl.carousel',function(){}) 中看到总项目,但我怎样才能得到该值以在 owl.trigger('to.owl.carousel', items) 中使用
var owl = $('.owl-carousel')
// on initialise...
owl.on('initialize.owl.carousel', event => {
//get this var out????
var items = event.item.count
})
// attach the carousel and set the params
owl.owlCarousel({
margin: 50,
nav: false
})
//event handler
//HERE I WANT TO USE THE ITEMS VALUE
owl.trigger('to.owl.carousel', items)
控制台中的错误
Uncaught ReferenceError: items is not defined
【问题讨论】:
-
这么简单....
owl.trigger('to.owl.carousel', -1)谢谢@Alex-HM
标签: javascript jquery owl-carousel