| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <template>
- <div>
- <div v-if="videoPauseShow" class="video-mask" @click="handlePlayVideo">
- <el-icon class="video-mask-play" :size="iconSize"><VideoPlay /></el-icon>
- </div>
- <video
- ref="videoRef"
- :key="videoUrl"
- type="video/mp4"
- :muted="muted"
- :preload="preload"
- :controls="controls"
- disablepictureinpicture
- :style="{ objectFit: 'contain', width: '100%', height: videoHeight }"
- @pause="handlePauseVideo"
- @play="handlePlayVideo"
- >
- <source :src="videoUrl" />
- </video>
- </div>
- </template>
- <script setup>
- import { ref } from 'vue';
- import { ElIcon } from 'element-plus';
- import { VideoPlay } from '@element-plus/icons-vue';
- const props = defineProps({
- videoUrl: {
- type: String,
- required: true,
- },
- iconSize: {
- type: Number,
- default: 140,
- },
- controls: {
- type: Boolean,
- default: true,
- },
- muted: {
- type: Boolean,
- default: true,
- },
- preload: {
- type: String,
- default: 'auto',
- },
- videoHeight: {
- type: String,
- default: '432px',
- },
- });
- const videoRef = ref(null);
- const videoPauseShow = ref(true);
- const handlePlayVideo = () => {
- videoPauseShow.value = false;
- if (videoRef.value) {
- videoRef.value.play();
- }
- };
- const handlePauseVideo = () => {
- videoPauseShow.value = true;
- if (videoRef.value) {
- videoRef.value.pause();
- }
- };
- </script>
- <style scoped>
- .video-mask {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: rgba(0, 0, 0, 0.5);
- display: flex;
- align-items: center;
- justify-content: center;
- color: #fff;
- z-index: 1;
- }
- .video-mask-play {
- cursor: pointer;
- }
- .video-mask-play:hover {
- animation: warn 1.5s ease-out infinite;
- }
- @keyframes warn {
- 0% {
- transform: scale(1);
- opacity: 1;
- }
- 100% {
- transform: scale(1.4);
- opacity: 0;
- }
- }
- </style>
|