单击图标图像(播放背景视频)时,从单击位置播放弹出窗口中的视频

时间:2019-12-27 10:04:50

标签: javascript jquery css popup html5-video

正在播放背景视频。单击播放图标后,视频应开始在弹出窗口中播放。但是视频应该从单击的时间和位置开始连续播放。

https://jsfiddle.net/Pavankumar_Kori/t1wupLmv/10/

示例:

如果单击“播放”,则正在播放(自动播放)背景视频-

$( document ).ready(function() {
  $('#headerVideoLink').magnificPopup({
    type:'inline',
    midClick: true // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href.
  });
}); 
@charset "utf-8";
/* CSS Document */

#videoContainer {
  position: absolute;
  min-height: 25rem;
  width: 100%;
  overflow: hidden;
}

#videoContainer video {
  position: absolute;
  top: 50%;
  left: 50%;
  width: auto;
  height: auto;
  min-width: 100%;
  min-height: 100%;
  z-index: 0;
  -ms-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -webkit-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
}

#videoContainer .position {
  position: absolute;
  z-index: 2;
}

#videoContainer .overlay {
  position: absolute;
  top: 0;
  left: 0;
  background: #000000;
  height: 100%;
  width: 100%;
  opacity: 0.4;
  z-index: 1;
}

#headerPopup{
  width:100%;
  margin:0 auto;
}

#headerPopup video{
  width:100%;
  margin:0 auto;
}

.mfp-close-btn-in .mfp-close {
  color: #fff;
  opacity: 1;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/jquery.magnific-popup.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/magnific-popup.min.css" rel="stylesheet"/>
<link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<section id="videoContainer">
  <div class="overlay"></div>
  <video playsinline="playsinline" autoplay="autoplay" muted="muted" loop="loop">
    <source src="https://videos.dailymail.co.uk/video/mol/2015/10/21/404258251173707140/1024x576_404258251173707140.mp4" type="video/mp4">
  </video>
  <div class="container-fluid position h-100">
    <div class="d-flex h-100 text-center align-items-center">
      <div class="w-100">
        <a href="#headerPopup" id="headerVideoLink" target="_blank"><img src="https://image.flaticon.com/icons/png/512/0/375.png" alt="Smiley face" height="80" width="80"></a>
      </div>
    </div>
  </div>
  <div id="headerPopup" class="mfp-hide embed-responsive embed-responsive-21by9">
    <video playsinline="playsinline" autoplay="autoplay" controls="controls" muted="muted" loop="loop">
      <source src="https://videos.dailymail.co.uk/video/mol/2015/10/21/404258251173707140/1024x576_404258251173707140.mp4" type="video/mp4">
    </video>
  </div>
</section>

以x秒/分钟的速度

icon。在Popup中,它应该从x秒/分钟开始连续播放

1 个答案:

答案 0 :(得分:1)

您可以在宏大的弹出窗口中使用回调函数...然后使用简单的javascript将背景视频的currentTime更新为弹出视频。

这是演示

$( document ).ready(function() {
  $('#headerVideoLink').magnificPopup({
    type:'inline',
    midClick: true, // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href.
    callbacks: {
      elementParse: function(item) {
        var bannerVid = $('#videoContainer').children('video')[0].currentTime;
        $('#videoContainer').children('video')[0].pause();
        $('#headerPopup').children('video')[0].currentTime = bannerVid;
        $('#headerPopup').children('video')[0].play();
      },
      close: function(){
        var vidTime = $('#headerPopup').children('video')[0].currentTime;
        $('#headerPopup').children('video')[0].pause();
        $('#videoContainer').children('video')[0].currentTime = vidTime;
        $('#videoContainer').children('video')[0].play();
      }
    }
  });
});
@charset "utf-8";
/* CSS Document */

#videoContainer {
  position: absolute;
  min-height: 25rem;
  width: 100%;
  overflow: hidden;
}

#videoContainer video {
  position: absolute;
  top: 50%;
  left: 50%;
  width: auto;
  height: auto;
  min-width: 100%;
  min-height: 100%;
  z-index: 0;
  -ms-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -webkit-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
}

#videoContainer .position {
  position: absolute;
  z-index: 2;
}

#videoContainer .overlay {
  position: absolute;
  top: 0;
  left: 0;
  background: #000000;
  height: 100%;
  width: 100%;
  opacity: 0.4;
  z-index: 1;
}

#headerPopup{
  width:100%;
  margin:0 auto;
}

#headerPopup video{
  width:100%;
  margin:0 auto;
}

.mfp-close-btn-in .mfp-close {
  color: #fff;
  opacity: 1;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/magnific-popup.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/jquery.magnific-popup.min.js"></script>

<section id="videoContainer">
  <div class="overlay"></div>
  <video playsinline="playsinline" autoplay="autoplay" muted="muted" loop="loop">
    <source src="https://videos.dailymail.co.uk/video/mol/2015/10/21/404258251173707140/1024x576_404258251173707140.mp4" type="video/mp4">
  </video>
  <div class="container-fluid position h-100">
    <div class="d-flex h-100 text-center align-items-center">
      <div class="w-100">
        <a href="#headerPopup" id="headerVideoLink" target="_blank"><img src="https://image.flaticon.com/icons/png/512/0/375.png" alt="Smiley face" height="80" width="80"></a>
      </div>
    </div>
  </div>
  <div id="headerPopup" class="mfp-hide embed-responsive embed-responsive-21by9">
    <video playsinline="playsinline" autoplay="autoplay" controls="controls" muted="muted" loop="loop">
      <source src="https://videos.dailymail.co.uk/video/mol/2015/10/21/404258251173707140/1024x576_404258251173707140.mp4" type="video/mp4">
    </video>
  </div>
</section>