Owl carousel 检查项目计数以做某事
Owl carousel checks item count for doing something
我有一个 owl 旋转木马,我想写一个函数来检查项目数是否等于 1,然后禁用相应的导航箭头。
请帮我做,这是我试过的(一个函数将显示控制台中的项目数及其各自的索引,但它不起作用)
var owl = $('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
responsiveClass: true,
dots: false,
responsive: {
0: {
items: 1,
nav: false,
},
767: {
items: 2,
nav: false
},
1000: {
items: 3,
nav: true,
loop: false
},
onDragged : callback
}
})
function callback() {
var items = event.items.count;
var item = event.item.index;
console.log(items,item);
}
我们这样试试:
var owl = $('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
responsiveClass: true,
dots: false,
responsive: {
0: {
items: 1,
nav: false,
},
767: {
items: 2,
nav: false
},
1000: {
items: 3,
nav: true,
loop: false
},
onDragged : callback
}
})
function callback(event) {
var navValue = $(this).get(0).options.nav;
console.log('Old nav value = ' + navValue);
if (event.item.count == 1) {
//if total count of items = 1 - we change value
navValue = false;
//check if changed
console.log('New nav value = ' + navValue);
}
};
这可以通过一个选项来完成:
loop: false
做你想做的。
我有一个 owl 旋转木马,我想写一个函数来检查项目数是否等于 1,然后禁用相应的导航箭头。
请帮我做,这是我试过的(一个函数将显示控制台中的项目数及其各自的索引,但它不起作用)
var owl = $('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
responsiveClass: true,
dots: false,
responsive: {
0: {
items: 1,
nav: false,
},
767: {
items: 2,
nav: false
},
1000: {
items: 3,
nav: true,
loop: false
},
onDragged : callback
}
})
function callback() {
var items = event.items.count;
var item = event.item.index;
console.log(items,item);
}
我们这样试试:
var owl = $('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
responsiveClass: true,
dots: false,
responsive: {
0: {
items: 1,
nav: false,
},
767: {
items: 2,
nav: false
},
1000: {
items: 3,
nav: true,
loop: false
},
onDragged : callback
}
})
function callback(event) {
var navValue = $(this).get(0).options.nav;
console.log('Old nav value = ' + navValue);
if (event.item.count == 1) {
//if total count of items = 1 - we change value
navValue = false;
//check if changed
console.log('New nav value = ' + navValue);
}
};
这可以通过一个选项来完成:
loop: false
做你想做的。