1. <template>
    2. <div id="small"></div> //小窗口,一定要放在传送门前面
    3. <div class="big">
    4. <Teleport to="#small" :disabled="isTeleport">
    5. <div id="mse"></div>
    6. </teleport>
    7. </div>
    8. <div id="target"></div>//检测是否在视口内
    9. <div style="width: 100%;height: 2000px;"></div>
    10. </template>
    11. <script setup lang="ts">
    12. import Player from 'xgplayer' //西瓜视频
    13. import { useIntersectionObserver } from '@vueuse/core'
    14. import { onMounted, ref } from 'vue';
    15. let isTeleport = ref(true)
    16. onMounted(() => {
    17. const { stop } = useIntersectionObserver(
    18. document.querySelector('#target') as HTMLElement,
    19. ([{ isIntersecting }], observerElement) => {
    20. isTeleport.value = isIntersecting
    21. },
    22. )
    23. let player = new Player({
    24. id: 'mse',
    25. url: 'https://cdn.cnbj1.fds.api.mi-img.com/product-images/xiaomi12proarp71i/video1-1.mp4',
    26. width: '100%',
    27. height: '100%'
    28. });
    29. })
    30. </script>
    31. <style>
    32. #small {
    33. position: fixed;
    34. right: 10vw;
    35. bottom: 10vh;
    36. width: 18vw;
    37. height: 20vh;
    38. }
    39. </style>