<#listvideoListasvideo>                       ...">
技术文章
swiper 视频无限自动轮播 无缝轮播的实现
发布日期:2019-06-29 阅读次数:2735 字体大小:

本案例用的swiper-4.2.2.min.js 和 swiper-4.2.2.min.css

 

html代码:       

             

                    

                        <#list videoList as video>
                            

                            
                            

                        
 
                    

                    
                    
 

             
 

 

javascript代码:
 
     var mySwiper2 = new Swiper('#swiper2', {
                loop : true,
                speed : 2000,
                autoplay : {
                    delay : 5000,
                    stopOnLastSlide : false,
                    disableOnInteraction : true,
                },
                pagination : '.swiper-pagination'
            })
     
            mySwiper2.el.onmouseover = function() { //鼠标进入
                mySwiper2.autoplay.stop();  //轮播停止
            }
            mySwiper2.el.onmouseout = function() { //鼠标离开
                var v_len = $("#swiper2 .swiper-slide").find("video").length
                    for(var i = 0;i                       $("#swiper2 .swiper-slide").find("video").get(i).pause(); //把所有停止
                    }
                mySwiper2.autoplay.start(); //轮播开始
            }
     
            $("#swiper2 .swiper-slide video").on("click", function() {
                var isPaused = $(this).get(0).paused  //视频是否在播放
                if(isPaused){ // 我点击的这个是暂停的
                    $(this).get(0).play(); //播放
                }else{
                    $(this).get(0).pause(); //停止
                }
            });