Reputation: 4150
I have created a slide show with owlcarousel2 library, and I would like to set for each slide, a different movement to appear on the screen.
For example now all the slides appears on the screen from right to left, as in a normal slide show. Is possible to set to each slide different appear movement like from left to right for some and from right to left for other?
This is my code:
<section class="welcome_area" id="home">
<div class="welcome_slides">
<div class="single_slide">
<div class="slide_text">
<div class="table">
<div class="table_cell">
<center><img src="img/Oregon_Duck_website.gif" /></center>
</div>
</div>
</div>
</div>
<!-- Slide -->
<div class="single_slide">
<div class="slide_text">
<div class="table">
<div class="table_cell">
<center><img src="img/Oregon_Football_1_Black-Gray-Yellow.gif" /></center>
</div>
</div>
</div>
</div>
</div>
</section>
and js:
if ($.fn.owlCarousel) {
$(".welcome_slides").owlCarousel({
items: 1,
margin: 0,
loop: true,
nav: true,
navText: ['<i class="fa fa-chevron-left" aria-hidden="true"></i>', '<i class="fa fa-chevron-right" aria-hidden="true"></i>'],
dots: false,
autoplay: true,
autoplayTimeout: 7000,
smartSpeed: 500,
autoplayHoverPause: false
});
}
Upvotes: 0
Views: 1567
Reputation: 1657
There are 2 main things you need to do:
Include animate.css in your page.
Create a custom function to select from an array of animation provided from animate.css
function getRandomAnimation() {
var animationList = ['bounce', 'zoomIn', 'flipInX', 'flash', 'pulse', 'rubberBand', 'jello'];
return animationList[Math.floor(Math.random() * animationList.length)];
}
Once you have both things set up you just need to initialize owl carousel and set animateOut
and animateIn
to get the random value from getRandomAnimation()
function.
var owl = $('.owl-carousel');
owl.owlCarousel({
animateOut: getRandomAnimation,
animateIn: getRandomAnimation,
items: 1,
margin: 30,
stagePadding: 30,
smartSpeed: 450,
autoplay: true,
autoplayTimeout: 2000
});
In the below example I'm creating a random slide animation with autoplay set to 2 seconds just to show you each slide is picking up the different animation.
Example:
$(document).ready(function() {
var owl = $('.owl-carousel');
//init default carousel
owl.owlCarousel({
animateOut: getRandomAnimation,
animateIn: getRandomAnimation,
items: 1,
margin: 30,
stagePadding: 30,
smartSpeed: 450,
autoplay: true,
autoplayTimeout: 2000
});
function getRandomAnimation() {
var animationList = ['bounce', 'zoomIn', 'flipInX', 'flash', 'pulse', 'rubberBand', 'jello'];
return animationList[Math.floor(Math.random() * animationList.length)];
}
});
.owl-carousel {
max-width: 300px;
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.carousel.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.theme.default.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/owl.carousel.min.js"></script>
<div class="owl-carousel owl-theme">
<div class="item"><img src="https://dummyimage.com/600x400/287321/fff" />
<h4>1</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/1fb84f/fff" />
<h4>2</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/3369cc/fff" />
<h4>3</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/287321/fff" />
<h4>4</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/9253d6/fff" />
<h4>5</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/948b46/fff" />
<h4>6</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/239cba/fff" />
<h4>7</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/cc43c1/fff" />
<h4>8</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/7d2477/fff" />
<h4>9</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/a3541f/fff" />
<h4>10</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/225911/fff" />
<h4>11</h4>
</div>
<div class="item"><img src="https://dummyimage.com/600x400/21378f/fff" />
<h4>12</h4>
</div>
</div>
Upvotes: 1