触摸播放视频,并用iframe实现播放外站视频

效果:

在这里插入图片描述

html:

        <div
                :style="{ height: homedivh }"
                class="rightOne_content_div_div"
                @mouseenter="divSeenter(i)"
                @mouseleave="divLeave(i)"
                @click="ItemClick(i)"
              >
                <!-- isUser是否是用户上传 -->
                <div
                  v-if="i.isUser"
                  style="
                    width: 20px;
                    position: absolute;
                    height: 20px;
                    right: 1%;
                    top: 2%;
                  "
                >
                  <svg
                    t="1715653701623"
                    class="icon"
                    viewBox="0 0 1024 1024"
                    version="1.1"
                    xmlns="http://www.w3.org/2000/svg"
                    p-id="8731"
                    width="100%"
                    height="100%"
                  >
                    <path
                      d="M512 981.333333C252.8 981.333333 42.666667 771.2 42.666667 512S252.8 42.666667 512 42.666667s469.333333 210.133333 469.333333 469.333333-210.133333 469.333333-469.333333 469.333333z m36.394667-283.093333l80.810666 48.085333c19.968 11.904 34.602667 2.688 32.426667-20.736l-9.130667-98.048c-2.218667-23.509333 8.96-56.277333 24.96-73.386666l61.610667-66.005334c16.128-17.322667 10.410667-34.986667-12.373333-39.850666l-88.064-18.858667c-23.04-4.949333-50.176-25.941333-61.098667-47.018667l-45.738667-88.234666c-10.965333-21.205333-28.672-21.077333-39.594666 0l-45.738667 88.234666c-10.965333 21.162667-38.314667 42.112-61.098667 47.018667l-88.064 18.858667c-23.04 4.949333-28.373333 22.698667-12.373333 39.850666l61.610667 66.005334c16.128 17.28 27.136 49.962667 24.96 73.386666l-9.130667 98.048c-2.218667 23.509333 12.330667 32.725333 32.426667 20.736l80.810666-48.085333c19.968-11.904 52.693333-11.946667 72.789334 0z"
                      p-id="8732"
                      fill="#FFA53D"
                    ></path>
                  </svg>
                </div>
                <img
                  v-show="!i.showImage"
                  class="rightOne_content_div_img"
                  :src="i.cover"
                  alt=""
                />
                <div class="rightOne_content_div_img_div">
                  <CrossSiteVideo
                    class="rightOne_content_div_img"
                    v-if="i.showImage"
                    :src="zfgvideo"
                    :controls="false"
                    @click="ItemClick(i)"
                  />
                </div>

                <div class="rightOne_content_div_img">
                  <div class="rightOne_content_div_time">
                    <!-- {{ i.duration | formatTime }} -->
                  </div>
                </div>
              </div>

js:

    // 首页鼠标移入
    divSeenter(i) {
      console.log("🚀 ~ divSeenter ~ i:", i);
      this.zfgvideo = `${i.videoUrl}`;
      i.showImage = true;
      console.log("🚀 ~ divSeenter ~  this.zfgvideo:", this.zfgvideo);
      this.$forceUpdate();
    },
    divLeave(i) {
      i.showImage = false;
      this.zfgvideo = "";
      this.$forceUpdate();
    },

组件CrossSiteVideo:

<template>
  <iframe @load="syncAttrs" ref="vref" frameborder="0" src="/video.html"></iframe>
</template>

<script setup name="CrossSiteVideo">
import Vue, { reactive, getCurrentInstance, onBeforeUnmount, ref, watch, onMounted, defineEmits, defineProps } from "vue";

const vref = ref();

const props = defineProps(['src','controls']);
const emits = defineEmits(['click']);
const events = {
  click: (...arg) => emits('click', ...arg),
}

const syncEvents = (isDestroy) => {
  const win = vref?.value?.contentWindow;
  if (typeof win?.updateVideoEvents === 'function') {
    win.updateVideoEvents(events,isDestroy)
  }
}
const syncAttrs = () => {
  const win = vref?.value?.contentWindow;
  if (typeof win?.updateVideoAttributes === 'function') {
    syncEvents();
    win.updateVideoAttributes(props)
  }
}

// onMounted(syncAttrs);
watch(props, syncAttrs);
onBeforeUnmount(() => {
  syncEvents(true);
});

</script>

<style scoped lang="less">
iframe {
  -ms-overflow-style: none;
  /* IE和Edge */
  scrollbar-width: none;
  /* Firefox */
}
</style>

相关推荐

  1. Vue实现视频播放

    2024-05-14 17:06:16       25 阅读
  2. dplayer播放hls格式视频自动开始播放

    2024-05-14 17:06:16       65 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-14 17:06:16       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-14 17:06:16       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-14 17:06:16       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-14 17:06:16       20 阅读

热门阅读

  1. nodejs + express 接口统一返回错误信息

    2024-05-14 17:06:16       13 阅读
  2. Auto.js如何打包成APK文件

    2024-05-14 17:06:16       28 阅读
  3. C++ primer plus 第五章编程练习

    2024-05-14 17:06:16       37 阅读
  4. 面试集中营—Linux篇

    2024-05-14 17:06:16       12 阅读
  5. 比特币能否跨过量子时代的这道槛?

    2024-05-14 17:06:16       12 阅读
  6. 【Python】Python中的logging模块介绍和示例

    2024-05-14 17:06:16       16 阅读
  7. 【FFmpeg】调用FFmpeg和SDL2进行解码后渲染播放

    2024-05-14 17:06:16       18 阅读
  8. 申请免费的Let‘s Encrypt 通配符 HTTPS 证书

    2024-05-14 17:06:16       16 阅读
  9. Python实战开发及案例分析(21)—— 广度优先

    2024-05-14 17:06:16       15 阅读
  10. Python数独游戏

    2024-05-14 17:06:16       16 阅读
  11. 【Python系列-01学习路线-01基础】03变量

    2024-05-14 17:06:16       26 阅读