网页视频播放插件

1.HTML代码

  <div class="video-popup">
    <div class="video-container">
      <video id="video-player" controls>
        <source src="" type="video/mp4" />
      </video>
      <button id="close-btn" @click="closeVideoPopup()">关闭</button>
    </div>
  </div>

2.CSS代码

.video-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.651);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.video-container {
  position: relative;
}

#video-player {
  width: 800px;
  height: 450px;
  background: #0000009d;
}

#close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  color: #ffffff;
}

#close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  color: #ffffff;
  width: 30px;
  height: 30px;
  border-radius: 15px;
}

3.js代码

function openVideoPopup(coverVideo) {
  var videoPopup = document.querySelector('.video-popup')
  console.log('新的视频id', coverVideo)
  // 获取视频源标签
  var source = document.querySelector('#video-player source')

  // 更改src属性
  source.src = coverVideo

  // 获取视频元素
  var video = document.getElementById('video-player')

  // 重新加载视频
  video.load()
  videoPopup.style.display = 'flex'
}

function closeVideoPopup() {
  var videoPopup = document.querySelector('.video-popup')
  videoPopup.style.display = 'none'
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值