var width=$(window).width(); // $(".banner .swiper-slide").each(function(){ // if($(this).has('video').length){ // var src=$(this).find('video').attr('data-src'); // $(this).find('video').attr('src',src); // } // }); // 获取第一个视频时长 $(".banner .swiper-slide").each(function(){ if($(this).has('video').length){ $(this).attr('id','b_has_v'); $(this).find('video').attr('id','video'); return false; }; }); // 移动端去除视频 // if (width < 1025) { // $('#b_has_v').remove() // }; var audioe2 = document.getelementbyid("video"); // 如果swiper有视频 if(audioe2){ // 上传了视频,等待视频加载完 audioe2 .onloadedmetadata = function() { var tol=audioe2.duration; // tol=tol*1000; var banner_swiper = new swiper('.banner .swiper-container',{ speed: 600, loop: true, // autoplay:false, autoplay: { delay: 4000, stoponlastslide: false, disableoninteraction: false, }, navigation: { nextel: '.banner-button-next', prevel: '.banner-button-prev', }, pagination: { el: '.banner-pagination', clickable: true, }, on: { init: function(){ $('.banner .swiper-slide').eq(this.activeindex).find('.text').addclass('active'); swiperanimatecache(this); //隐藏动画元素 swiperanimate(this); //初始化完成开始动画 }, slidechangetransitionend: function(){ swiperanimate(this); //每个slide切换结束时也运行当前slide动画 // this.slides.eq(this.activeindex).find('.ani').removeclass('ani'); //动画只展现一次,去除ani类名 }, slidechangetransitionstart: function(){ var _target = this; var curvideo = this.$el.find(".swiper-slide-active").find("video"); // tol=curvideo.duration; //暂停所有视频 function pauseall(ele){ ele.find("video").each(function(){ $(this)[0].pause(); }); } pauseall(this.$el); //轮播间隔时间 //console.log(tol) _target.params.autoplay.delay = tol*1000; //判断当前激活元素是否有视频 if(curvideo.length > 0){ //console.log("有视频!"); this.autoplay.stop(); curvideo[0].currenttime = 0; curvideo[0].play(); curvideo[0].removeeventlistener('ended', function (){}, false); curvideo[0].addeventlistener('ended', function (){ if($('.banner .sign').hasclass('active')){ // 此时是暂停状态 }else{ _target.slidenext(); } }, false); }else{ //console.log("无视频!"); _target.params.autoplay.delay=4000; _target.autoplay.start(); flag=true; } }, }, }); } }else{ // 没上传视频 var banner_swiper = new swiper('.banner .swiper-container',{ speed: 600, loop:true, autoplay: { delay: 4000, stoponlastslide: false, disableoninteraction: false, }, pagination: { el: '.banner-pagination', clickable: true, }, // navigation: { // nextel: '.banner-button-next', // prevel: '.banner-button-prev', // }, on: { init: function(){ $('.banner .swiper-slide').eq(this.activeindex).find('.text').addclass('active'); swiperanimatecache(this); //隐藏动画元素 swiperanimate(this); //初始化完成开始动画 }, slidechangetransitionend: function(){ swiperanimate(this); //每个slide切换结束时也运行当前slide动画 // this.slides.eq(this.activeindex).find('.ani').removeclass('ani'); //动画只展现一次,去除ani类名 }, slidechangetransitionstart: function(){ }, }, }); }