日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

示例簡介

本文介紹在banner輪播基礎上實現播放視頻功能,有兩種播放方式:

1、點擊播放按鈕,在banner圖位置播放視頻(效果如下);

2、點擊播放按鈕,全屏播放視頻。

 

實現過程

1、兩種播放方式,css樣式共用如下:

* {  padding: 0;  margin: 0;}.swiper-container {  width: 100%;  height: 211px;}.video {  position: absolute;  z-index: 1;  top: 0;  left: 0;  width: 100%;  height: 100%;  display: none;  background-color: rgba(0, 0, 0, 0.5);}.loading-box {  width: 100%;  position: absolute;  top: 0;  left: 0;  height: 100%;  font-size: 0;}.loading-box .video-img {  width: 100%;  height: 100%;}.loading-box .palying-img {  position: absolute;  top: 50%;  left: 50%;  transform: translateX(-50%) translateY(-50%);  opacity: 1;  transition: opacity 0.3s;}.loading-box .loading-img {  position: absolute;  top: 50%;  left: 50%;  transform: translateX(-50%) translateY(-50%);  opacity: 0;  transition: opacity 0.3s;}.loading-box.loading .loading-img {  animation: loading 1s infinite;  -webkit-animation: loading 1s infinite;  opacity: 1;}.loading-box.loading .palying-img {  display: none;}.diy-buttons {  overflow: hidden;  text-align: center;}.diy-buttons a {  float: left;  width: 50%;}@keyframes loading {  from {    transform: translateX(-50%) translateY(-50%) rotate(0deg);  }  to {    transform: translateX(-50%) translateY(-50%) rotate(360deg);  }}

2、第一種播放方式,html和js代碼如下:

1)“onSlideChangeEnd”用來輪播結束回調函數“removeLoading”,移除加載效果,解決切換過快有時候還顯示加載效果;

2)由于swiper為了循環輪播,復制了多一份數據,所以里面的video獲取未使用ID;

3)監聽video的狀態“play”和“pause”來控制輪播或暫停輪播,增加體驗。

<!DOCTYPE html><html lang="en"><head>  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  <meta name="renderer" content="webkit">  <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />  <title>banner輪播視頻</title>  <link rel="shortcut icon" href="#" />  <link rel="stylesheet" type="text/css" href="css/style.css" />  <link href="css/swiper.min.css" rel="stylesheet"></head><body>  <div class="banner">    <div class="swiper-container">      <div class="swiper-wrApper">        <div class="swiper-slide">          <video type="video/mp4" width="100%" height="211" id="video-1" class="video" src="video/1.mp4" webkit-playsinline="true" playsinline="true" x5-video-player-type="h5" x5-video-orientation="portrait" x5-video-player-fullscreen="true" onplaying="removeLoading()"></video>          <div class="loading-box video-play" data-id="video-1">            <img class="video-img" alt="" src="img/1.jpg">            <img src="img/palying.png" alt="" class="palying-img">            <img src="img/load-c.png" alt="" class="loading-img">          </div>        </div>        <div class="swiper-slide">          <video type="video/mp4" width="100%" height="211" id="video-2" class="video" src="video/2.mp4" webkit-playsinline="true" playsinline="true" x5-video-player-type="h5" x5-video-orientation="portrait" x5-video-player-fullscreen="true" onplaying="removeLoading()"></video>          <div class="loading-box video-play" data-id="video-2">            <img class="video-img" alt="" src="img/2.jpg">            <img src="img/palying.png" alt="" class="palying-img">            <img src="img/load-c.png" alt="" class="loading-img">          </div>        </div>      </div>    </div>  </div>  <script src="js/swiper.min.js"></script>  <script src="js/jquery-1.12.4.min.js"></script>  <script>  $(function() {    // 設置swiper參數    var mySwiper = new Swiper('.swiper-container', {      autoplay: 3000, // 3000          loop: true, // 循環模式選項      pagination: {        el: '.swiper-pagination',      },      onSlideChangeEnd: function() {        removeLoading();      }    });    $('.video-play').click(function(e) {            $('.video').css('display', 'none');      var video = $(this).siblings('video.video');      video.css('display', 'block');      playVideo(mySwiper, video);    });  });  // 全屏播放視頻函數  function playVideo(mySwiper, video) {    $('.loading-box').addClass('loading');    video[0].play();    // 監聽播放狀態    video.on('play', function() {      mySwiper.stopAutoplay();    });    // 監聽暫停狀態    video.on('pause', function() {      mySwiper.startAutoplay();      $('.video').css('display', 'none');    });  }  function removeLoading() {    $('.loading-box').removeClass('loading');  }</script></body></html>

3、第二種播放方式,html和js代碼如下:

1)使用“webkitEnterFullScreen”全屏播放,兼容性比較好,可以在Android/ target=_blank class=infotextkey>安卓和蘋果正常使用。

<!DOCTYPE html><html lang="en"><head>  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  <meta name="renderer" content="webkit">  <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />  <title>banner輪播視頻</title>  <link rel="shortcut icon" href="#" />  <link rel="stylesheet" type="text/css" href="css/style.css" />  <link href="css/swiper.min.css" rel="stylesheet"></head><body>  <div class="banner">    <div class="swiper-container">      <div class="swiper-wrapper">        <div class="swiper-slide">          <video type="video/mp4" width="100%" height="211" id="video-1" class="video" src="video/1.mp4" webkit-playsinline="true" playsinline="true" x5-video-player-type="h5" x5-video-orientation="portrait" x5-video-player-fullscreen="true" onplaying="removeLoading()" onwebkitfullscreenchange="fullScreenChange(event)"></video>          <div class="loading-box video-play" data-id="video-1">            <img class="video-img" alt="" src="img/1.jpg">            <img src="img/palying.png" alt="" class="palying-img">            <img src="img/load-c.png" alt="" class="loading-img">          </div>        </div>        <div class="swiper-slide">          <video type="video/mp4" width="100%" height="211" id="video-2" class="video" src="video/2.mp4" webkit-playsinline="true" playsinline="true" x5-video-player-type="h5" x5-video-orientation="portrait" x5-video-player-fullscreen="true" onplaying="removeLoading()" onwebkitfullscreenchange="fullScreenChange(event)"></video>          <div class="loading-box video-play" data-id="video-2">            <img class="video-img" alt="" src="img/2.jpg">            <img src="img/palying.png" alt="" class="palying-img">            <img src="img/load-c.png" alt="" class="loading-img">          </div>        </div>      </div>    </div>  </div>  <script src="js/swiper.min.js"></script>  <script src="js/jquery-1.12.4.min.js"></script>  <script>  $(function() {    // 設置swiper參數    var mySwiper = new Swiper('.swiper-container', {      autoplay: 3000, // 3000          loop: true, // 循環模式選項      pagination: {        el: '.swiper-pagination',      }    });    $('.video-play').click(function(e) {      var idName = e.currentTarget.dataset.id;      $('#' + idName).css('display', 'block');      playVideo(idName);    });  });  // 全屏播放視頻函數  async function playVideo(idName) {    $('.loading-box').addClass('loading');    var video = document.getElementById(idName);    await video.play()    video.webkitEnterFullScreen()  }  function removeLoading() {    $('.loading-box').removeClass('loading');  }  function fullScreenChange(e) {    $('.loading-box').removeClass('loading');    var video = document.getElementById(e.target.id);    if (!video.webkitDisplayingFullscreen) {      video.pause();      $('.video').css('display', 'none');    }  }</script></body></html>

分享到:
標簽:播放 視頻
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定