问题
There are two owlCarousel working perfectly in one page but I want to change the default setting on each carousel. Once I changed the effects applying to both carousel.
What I've already tried
<script>
$(document).ready(function() {
$("#owl-demo").owlCarousel1({
navigation : false,
pagination : true,
items : 1
});
});
</script>
<script>
$(document).ready(function() {
$("#owl-example").owlCarousel();
});
</script>
I want to change the below settings for each carousle
$.fn.owlCarousel.options = {
items : 4,
itemsCustom : false,
itemsDesktop : [1199, 1],
itemsDesktopSmall : [979, 1],
itemsTablet : [768, 1],
itemsTabletSmall : false,
itemsMobile : [479, 1],
singleItem : false,
itemsScaleUp : false
}
回答1:
If you assign a variable to each of the div's you wish to target and then assign the options, example below;
$(document).ready(function() {
var one = $("#one");
var two = $("#two");
one.owlCarousel({
navigation : false, // Show next and prev buttons
slideSpeed : 300,
paginationSpeed : 400,
singleItem:true,
mouseDrag:false,
touchDrag:false
});
two.owlCarousel({
navigation : true, // Show next and prev buttons
slideSpeed : 300,
paginationSpeed : 400,
singleItem:true,
mouseDrag:false,
touchDrag:false,
navigationText : false,
rewindSpeed : 300,
});
});
回答2:
there are tow things you must do to let every owl slider have its own trigger
1- each one have it's own assignment like above
$(document).ready(function() {
var one = $("#one");
var two = $("#two");
one.owlCarousel({
navigation : false, // Show next and prev buttons
slideSpeed : 300,
paginationSpeed : 400,
singleItem:true,
mouseDrag:false,
touchDrag:false
});
two.owlCarousel({
navigation : true, // Show next and prev buttons
slideSpeed : 300,
paginationSpeed : 400,
singleItem:true,
mouseDrag:false,
touchDrag:false,
navigationText : false,
rewindSpeed : 300,
});
});
2- change the button class name
1st slider
<div class="customNavigation">
<a class="btn prev_one"><i class="fa fa-backward" aria-hidden="true"></i></a>
<a class="btn next_one"><i class="fa fa-forward" aria-hidden="true"></i></a>
<a class="btn play_one"><i class="fa fa-play" aria-hidden="true"></i></a>
<a class="btn stop_one"><i class="fa fa-pause" aria-hidden="true"></i></a>
</div>
2nd Slider
<div class="customNavigation">
<a class="btn prev_two"><i class="fa fa-backward" aria-hidden="true"></i></a>
<a class="btn next_two"><i class="fa fa-forward" aria-hidden="true"></i></a>
<a class="btn play_two"><i class="fa fa-play" aria-hidden="true"></i></a>
<a class="btn stop_two"><i class="fa fa-pause" aria-hidden="true"></i></a>
</div>
I wish it could be fine for you all
回答3:
To change the class of the nav or dots you can use the class options provided by Owl Carousel (https://owlcarousel2.github.io/OwlCarousel2/docs/api-classes.html)
$(document).ready(function() {
var one = $("#one");
var two = $("#two");
one.owlCarousel({
navContainerClass: '//YOUR CUSTOM CLASS',
dotsClass: '//YOUR CUSTOM CLASS'
});
two.owlCarousel({
navContainerClass: '//YOUR CUSTOM CLASS',
dotsClass: '//YOUR CUSTOM CLASS'
});
});
回答4:
js code
$("#fr-car").owlCarousel({
items: 1,
loop: false,
autoplay: true,
animateOut: 'fadeOut',
autoplayTimeout: 3000,
nav: true,
autoplayHoverPause: true
});
$('#nd-car').owlCarousel({
responsive:{
0:{
items:1,
nav:true
},
600:{
items:3,
nav:false
},
1000:{
items:5,
nav:true,
loop:false
}
}
})
HTML Code
<div id="fr-car" class="owl-carousel">
<div></div>
<div></div>
<div></div>
</div
<div id="nd-car" class="owl-carousel" >
<div></div>
<div></div>
<div></div>
</div
来源:https://stackoverflow.com/questions/25888864/mutlple-owl-carousel-in-one-page-with-different-setting