var flag = -1; var swiperBanner = new Swiper(".swiper-banner", { speed: 1000, cssMode: true, loop: true, autoplay: { delay: 6000, stopOnLastSlide: false, disableOnInteraction: false, }, navigation: { nextEl: ".swiper-btn a.next", prevEl: ".swiper-btn a.prev", }, pagination: { el: ".swiper-pgn", clickable: true, bulletActiveClass: 'active', renderBullet: function (index, className) { return '' } }, mousewheel: true, keyboard: true, on: { slideChange : function(){ var swiper = this; delay = this.params.autoplay.delay; anime({ targets: ".swiper-banner .swiper-pgn .active i", delay: 0, width: ["0", "100%"], easing: "linear", duration: delay-500 }); // 判断swiper-slide-active是否有视频 if($(".swiper-banner .swiper-slide:eq("+swiper.activeIndex+")").find("video").length > 0){ // console.log(swiper.activeIndex) if(flag == swiper.activeIndex) { return false; } flag = swiper.activeIndex; // 停止自动切换 swiper.autoplay.stop(); // 动态增加id setTimeout(function(){ swiper.autoplay.stop(); $(".swiper-banner .swiper-slide-active video").attr("id","video_"+swiper.activeIndex); var _video= document.getElementById("video_"+swiper.activeIndex); // 播放视频 _video.play(); // 切换后重新播放视频 _video.currentTime = 0; // 静音 _video.volume = 0; // 监听视频播放结束 _video.addEventListener('ended', function () { $(".swiper-banner .swiper-slide video").attr("id",""); swiper.slideNext(); //重新开始轮播banner swiper.autoplay.start(); }); }, 10); } } } });