要将Animate.css与Owl Carousel一起使用,您需要在更改幻灯片时手动触发Animate.css类。 以下是一个示例:
HTML:
Slide 1
Slide 2
Slide 3
CSS:
.animate__animated {
animation-duration: 1s;
}
.owl-item.active .animate__animated {
opacity: 1;
}
.owl-item.active .animate__animated.animate__fadeInLeft {
animation-name: fadeInLeft;
}
.owl-item.active .animate__animated.animate__fadeInRight {
animation-name: fadeInRight;
}
.owl-item.active .animate__animated.animate__fadeInUp {
animation-name: fadeInUp;
}
.owl-item.active .animate__animated.animate__fadeInDown {
animation-name: fadeInDown;
}
JavaScript:
$('.owl-carousel').owlCarousel({
items: 1,
loop: true,
margin: 10,
URLhashListener: true,
autoplayHoverPause: true,
startPosition: 'URLHash',
animateOut: 'animate__fadeOut',
animateIn: 'animate__fadeIn',
smartSpeed: 450,
onTranslated: animated,
onInitialize: animated
})
function animated() {
let animatingElements = document.querySelectorAll('.owl-item.active .animate__animated')
for (let i = 0; i < animatingElements.length; i++) {
animatingElements[i].classList.add('animate__fadeInUp')
}
}
在此示例中,我们在包含文本的幻灯片上添加了“animate__animated”类。 然后,我们将在当前活动幻灯片下的要素上触发Animate.css类。 我们使用onTranslated函数来确保幻灯片动画在