Swiper
フェード(クロスフェード) 切替時に動画を自動で再生・一時停止させる(video/.mp4)
videoタグでmp4を読み込む
スライドを切り替えたら自動再生する
script
const mySwiper = new Swiper(".swiper", {
loop: true, //スライドの無限ループ
slidesPerView: 1, //表示枚数
effect: 'fade', // フェード
autoplay: {// スライドの自動再生
delay: 4000, // スライド間の遷移の遅延を設定
},
speed: 1500, // スライド切り替え速度
pagination: {
el: ".swiper-pagination",
clickable: true,
},
//動画再生
on: {
//スライダー遷移時(ドキュメント内の全動画を一時停止にする)
transitionStart: function () {
let videos = document.querySelectorAll("video");
Array.prototype.forEach.call(videos, function (video) {
video.pause();
});
},
//スライダー遷移完了後(アクティブスライドの動画を再生する)
transitionEnd: function () {
let activeIndex = this.activeIndex;
let activeSlide = document.getElementsByClassName("swiper-slide")[activeIndex];
let activeSlideVideo = activeSlide.getElementsByTagName("video")[0];
activeSlideVideo.play();
}
}
});
HTML
・1番目の動画のみ「autoplay」をつける