$require(['swiper'], function () { var isOne = false; const timePlay = 5000; $('.videoBanner img').removeAttr('title'); $('.videoBanner video').attr('playsinline', 'true'); $('.videoBanner video').attr('webkit-playsinline', 'true'); var videoBanner = new Swiper('.videoBanner', { speed: 2000, simulateTouch: false, observer: true, observeParents: true, observeSlideChildren: true, effect: 'fade', fadeEffect: { crossFade: true, }, on: { init: function () { // 定时器清除 clearTimeout(this.videoTimer); var sThis = this; let firstVideo = $('[data-silde="0"]').find('video'); setTimeout(function () { let first_Play = $('[data-silde="0"]').find('.videoContent .plyr__controls__item.plyr__control[data-plyr="play"]') first_Play.off().on('click', function () { clearTimeout(sThis.videoTimer); firstVideo[0].addEventListener('ended', function () { if (document.fullscreenElement) { document.exitFullscreen(); } else { sThis.videoTimer = setTimeout(function () { videoBanner.slideNext(); }, timePlay); } }); if (firstVideo[0].paused) { sThis.videoTimer = setTimeout(function () { videoBanner.slideNext(); }, timePlay); } }) }, 600) //判断video存在且在微信中 if (firstVideo.length > 0 && isWeixin()) { var u = navigator.userAgent; //判断android if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) { document.addEventListener('touchstart', function () { firstVideo[0].play() }) //判断iphone } else if (u.indexOf('iPhone') > -1) { document.addEventListener('WeixinJSBridgeReady', function () { firstVideo[0].play() }) } } else { firstVideo[0].play(); } document.addEventListener('fullscreenchange', function () { if (document.fullscreenElement) { clearTimeout(sThis.videoTimer); } else { if (firstVideo[0].paused) { sThis.videoTimer = setTimeout(function () { videoBanner.slideNext(); }, timePlay); } } }); firstVideo[0].addEventListener('ended', function () { if (document.fullscreenElement) { document.exitFullscreen(); } else { sThis.videoTimer = setTimeout(function () { videoBanner.slideNext(); }, timePlay); } }); }, transitionStart: function () { console.log(`slide[${[this.activeIndex]}] = ${isOne}`) if (isOne) return clearTimeout(this.videoTimer); var sThis = this; var activeSlide = this.slides[this.activeIndex]; var videoElement = $(activeSlide).find('video')[0]; var playButton = $(activeSlide).find('.videoContent .plyr__controls__item.plyr__control[data-plyr="play"]') if ((!videoElement || videoElement.paused) || sThis.isEnd) { sThis.videoTimer = setTimeout(function () { if (sThis.isEnd) { videoBanner.slideTo(0, 1000, false); } else { videoBanner.slideNext(); } }, timePlay); } playButton.off().on('click', function () { isOnePlay = false if (isOnePlay) return; clearTimeout(sThis.videoTimer); function handleVideoEnd() { if (document.fullscreenElement) { document.exitFullscreen(); } else { sThis.videoTimer = setTimeout(function () { videoBanner.slideNext(); }, timePlay); } } videoElement.addEventListener('ended', handleVideoEnd, { once: true }); if (videoElement.paused) handleVideoEnd() isOnePlay = true; }) }, transitionEnd: function () { isOne = false; } }, }); $('.p_btn_prev').click(function () { let c = $('.p_slide').length - 1; let isfirst = $('.swiper-slide-active').data('silde') == '0'; $('[data-silde]').each(function () { let v = $(this).find('video')[0]; if (v) { v.pause(); } }); if (isfirst) { videoBanner.slideTo(c, 1000, false); } else { videoBanner.slidePrev(); } }) $('.p_btn_next').click(function () { let c = $('.p_slide').length - 1; let islast = $('.swiper-slide-active').data('silde') == c; $('[data-silde]').each(function () { let v = $(this).find('video')[0]; if (v) { v.pause(); } }); if (islast) { videoBanner.slideTo(0, 1000, false); } else { videoBanner.slideNext(); } }) $('.videoBanner video').each(function () { let img = $(this).closest('.p_video').find('.p_videoPoster img').attr('src'); $(this).attr('poster', img); const player = new Plyr(this, { muted: true, clickToPlay: false, }); }); });