您的位置:首页 > 文旅 > 美景 > 深圳品牌设计公司深圳vi设计_集团网站设计方案_全球搜索引擎排名2022_2024年最新时事新闻

深圳品牌设计公司深圳vi设计_集团网站设计方案_全球搜索引擎排名2022_2024年最新时事新闻

2025/7/12 21:02:10 来源:https://blog.csdn.net/m0_53912016/article/details/144143427  浏览:    关键词:深圳品牌设计公司深圳vi设计_集团网站设计方案_全球搜索引擎排名2022_2024年最新时事新闻
深圳品牌设计公司深圳vi设计_集团网站设计方案_全球搜索引擎排名2022_2024年最新时事新闻

效果图

在这里插入图片描述

代码

<template><div class="video-container" @mouseover="showControls" @mouseleave="hideControlsAfterDelay"><videoref="video"@loadedmetadata="initializePlayer"@timeupdate="updateProgress"@ended="resetPlayer"width="640"height="360"src="./11.mp4"></video><!--video自带的属性设置controls="false" 禁用自带默认控件(直接不写才会展示自定义的控件)--><div v-if="isControlsVisible" class="controls"><button @click="playPause">{{ isPlaying ? 'Pause' : 'Play' }}</button><input type="range" min="0" :max="duration" v-model.number="currentTime" @input="seekTo" /><span>{{ formatTime(currentTime) }} / {{ formatTime(duration) }}</span><button @click="muteUnmute">{{ isMuted ? 'Unmute' : 'Mute' }}</button></div></div>
</template><script>
export default {data() {return {isControlsVisible: false,isPlaying: false,isMuted: false,currentTime: 0,duration: 0,controlsTimeout: null,};},methods: {playPause() {const video = this.$refs.video;if (this.isPlaying) {video.pause();} else {video.play();}this.isPlaying = !this.isPlaying;},seekTo(event) {const video = this.$refs.video;video.currentTime = event.target.value;},updateProgress() {this.currentTime = this.$refs.video.currentTime;},initializePlayer() {this.duration = this.$refs.video.duration;},resetPlayer() {this.currentTime = 0;this.isPlaying = false;},muteUnmute() {const video = this.$refs.video;video.muted = !video.muted;this.isMuted = video.muted; // 更新静音状态},// 可以添加一个计算属性来显示当前的播放/暂停和静音/取消静音文本computed: {isMuted() {return this.$refs.video.muted;},},showControls() {this.isControlsVisible = true;if (this.controlsTimeout) {clearTimeout(this.controlsTimeout);this.controlsTimeout = null;}},hideControlsAfterDelay() {this.controlsTimeout = setTimeout(() => {this.isControlsVisible = false;}, 3000); // 3秒后隐藏控件,时间可根据需要调整},formatTime(time) {const minutes = Math.floor(time / 60);const seconds = Math.floor(time % 60).toString().padStart(2, '0');return `${minutes}:${seconds}`;},},
};
</script><style scoped>
.video-container {position: relative;width: 640px;height: 360px;border: 1px solid #ccc;
}.controls {position: absolute;bottom: 10px;left: 10px;right: 10px;display: flex;justify-content: space-between;align-items: center;background: rgba(255, 255, 255, 0.7);padding: 5px;border-radius: 5px;
}.controls button,
.controls input[type="range"] {flex: 1;
}.controls input[type="range"] {margin: 0 10px;
}
</style>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com