$(".wel-banner .items").each(function(i,v){ var url = $(this).find("video").attr("data-src"); var _this = $(this); var videoElement = document.createElement('video'); // console.log(videoElement); videoElement.src = url; videoElement.addEventListener('loadedmetadata', function () { // 视频时长值的获取要等到这个匿名函数执行完毕才产生 var videoTime = videoElement.duration*1000/1; //得到时长为秒,小数,182.36 _this.attr('data-swiper-autoplay',videoTime) }); }) if($(".wel-banner .swiper-slide").length >1){ var banner = new Swiper('.wel-banner .swiper-container', { prevButton:'.wel-banner .swiper-button-prev', nextButton:'.wel-banner .swiper-button-next', pagination : '.wel-banner .swiper-pagination', paginationBulletRender: function (swiper, index, className) { return '' + '' + ''; }, paginationClickable: true, centeredSlides: true, slidesPerView: 1, spaceBetween: 0, initialSlide:0, speed:600, effect:'fade', autoplay : 6000, paginationClickable: true, // loop:true, slideToClickedSlide:true, autoplayDisableOnInteraction: false, lazyLoading : true, lazyLoadingInPrevNext : true, roundLengths : true, uniqueNavElements :false, noSwiping : true, onInit: function(swiper){ $(".wel-banner .secwen").removeClass('animate'); setTimeout(function(){ $(".wel-banner .swiper-slide-active .secwen").addClass('animate'); },100) var activeIndex = swiper.activeIndex; var videoIndex = $('.wel-banner .swiper-slide-active.videoboxs').index(); // var activeIndex = $('.wel-banner .swiper-slide-active').data('swiper-slide-index'); var banLen = $('.wel-banner .swiper-slide').length; $(".welbanner-pagination .li").eq(activeIndex).addClass("active").siblings().removeClass("active"); var nums = activeIndex+1; var nums2 = $(".wel-banner .swiper-slide").length; nums = nums>9?nums:'0'+nums; nums2 = nums2>9?nums2:'0'+nums2; $(".wel-banner .numslist .b1").html(nums) $(".wel-banner .numslist .b2").html(nums2) if(banLen==1){ swiper.stopAutoplay(); } if(videoIndex == activeIndex){ var srcv = $(".wel-banner .swiper-slide-active.videoboxs video").attr("data-src"); $(".wel-banner .swiper-slide-active.videoboxs video").attr("src",srcv); // swiper.stopAutoplay(); // $(".wel-banner .swiper-slide-active.videoboxs").find("video")[0].load(); // $(".wel-banner .swiper-slide-active.videoboxs").find("video")[0].play(); } if($('.wel-banner .videoboxs').length>0){ $('.wel-banner .swiper-slide-active.videoboxs video').on('ended',function(){ setTimeout(function(){ // swiper.slideNext(); // swiper.startAutoplay(); // swiper.params.autoplay = 6000; },500) }) } }, onTransitionStart: function(swiper){ $(".wel-banner .secwen").removeClass('animate'); setTimeout(function(){ $(".wel-banner .swiper-slide-active .secwen").addClass('animate'); },100) var activeIndex = swiper.activeIndex; var banLen = $('.wel-banner .swiper-slide').length; var videoIndex = $('.wel-banner .swiper-slide-active.videoboxs').index(); // var activeIndex = $('.wel-banner .swiper-slide-active').data('swiper-slide-index'); $(".welbanner-pagination .li").eq(activeIndex).addClass("active").siblings().removeClass("active"); var nums2 = $(".wel-banner .swiper-slide").length; var nums = activeIndex+1; nums = nums>9?nums:'0'+nums; nums2 = nums2>9?nums2:'0'+nums2; $(".wel-banner .numslist .b1").html(nums) $(".wel-banner .numslist .b2").html(nums2) if(banLen==1){ swiper.stopAutoplay(); } if(videoIndex == activeIndex){ var srcv = $(".wel-banner .swiper-slide-active.videoboxs video").attr("data-src"); $(".wel-banner .swiper-slide-active.videoboxs video").attr("src",srcv); // swiper.stopAutoplay(); // $(".wel-banner .swiper-slide-active.videoboxs").find("video")[0].load(); // $(".wel-banner .swiper-slide-active.videoboxs").find("video")[0].play(); } if($('.wel-banner .videoboxs').length>0){ $('.swiper-slide-active.videoboxs video').on('ended',function(){ setTimeout(function(){ // swiper.startAutoplay(); // swiper.params.autoplay = 6000; },800) }) } } }) $(".welbanner-pagination .li").on("click",function(){ $(".wel-banner .secwen").removeClass('animate'); setTimeout(function(){ $(".wel-banner .swiper-slide-active .secwen").addClass('animate'); },100) $(this).addClass("active").siblings().removeClass("active"); var index = $(this).index(); banner.slideTo(index,1000,false); }) // $(".welbanner-pagination .li").eq(0).click(); }else{ $(".wel-banner .secwen").addClass('animate'); $(".wel-banner video").attr("autoplay","autoplay"); $(".wel-banner video").attr("loop","loop"); } if($(window).innerWidth()<1024){ $(".wel-banner video").attr("scr",""); } gmains.backtops(0);