我使用 splide.js 轮播,我想使用 animate.css 为幻灯片之间的文本标题设置动画。
我使用 splide 事件: https ://splidejs.com/guides/events/
这是我使用的代码:
document.addEventListener( 'DOMContentLoaded', function () {
var splide = new Splide( '.slider', {
type: 'fade',
perPage: 1,
autoplay: true,
focus: 'center',
trimSpace: false,
rewind: true,
} ).mount();
splide.on( 'active', function() {
const element = document.querySelector('.title');
element.classList.add('animate__animated', 'animate__fadeInRight');
} );
splide.on( 'inactive', function() {
const element = document.querySelector('.title');
element.classList.remove('animate__animated', 'animate__fadeInRight');
} );
});
Codepen 示例: https ://codepen.io/haralake/pen/YzQObEK
第一张幻灯片得到了课程,但其他人没有。我想我以错误的方式使用事件,但我不知道问题出在哪里。