提供一个vue前端页面示例,样式使用elementui,页面包括光标悬停提示返回顶部的返回顶部组件、光标悬停放大的图片组件、还有一个光标悬停出现播放按钮的视频组件
时间: 2023-11-22 21:53:55 浏览: 88
以下是一个简单的Vue前端页面示例,样式使用element-ui库,包含光标悬停提示返回顶部的返回顶部组件、光标悬停放大的图片组件、以及一个光标悬停出现播放按钮的视频组件:
```vue
<template>
<div>
<back-to-top />
<image-zoom />
<video-play />
</div>
</template>
<script>
import BackToTop from "@/components/BackToTop.vue";
import ImageZoom from "@/components/ImageZoom.vue";
import VideoPlay from "@/components/VideoPlay.vue";
export default {
name: "ExamplePage",
components: {
BackToTop,
ImageZoom,
VideoPlay,
},
};
</script>
<style>
/* 样式使用 element-ui 库 */
</style>
```
其中,`BackToTop` 组件实现了光标悬停提示返回顶部的功能,代码如下:
```vue
<template>
<div class="back-to-top" v-show="visible" @click="backToTop">
<el-tooltip content="返回顶部" placement="left">
<i class="el-icon-arrow-up"></i>
</el-tooltip>
</div>
</template>
<script>
export default {
name: "BackToTop",
data() {
return {
visible: false,
};
},
mounted() {
window.addEventListener("scroll", this.handleScroll);
},
destroyed() {
window.removeEventListener("scroll", this.handleScroll);
},
methods: {
handleScroll() {
const scrollTop =
document.documentElement.scrollTop || document.body.scrollTop;
this.visible = scrollTop > 0;
},
backToTop() {
window.scrollTo({
top: 0,
behavior: "smooth",
});
},
},
};
</script>
<style scoped>
.back-to-top {
position: fixed;
right: 50px;
bottom: 50px;
z-index: 999;
font-size: 20px;
cursor: pointer;
opacity: 0.6;
transition: opacity 0.3s;
}
.back-to-top:hover {
opacity: 1;
}
</style>
```
`ImageZoom` 组件实现了光标悬停放大的图片组件功能,代码如下:
```vue
<template>
<el-image
class="image-zoom"
:src="src"
:fit="fit"
:preview-src-list="previewSrcList"
@mouseenter.native="showZoomIn"
@mouseleave.native="hideZoomIn"
ref="image"
>
<template #placeholder>
<div class="image-placeholder">{{ placeholder }}</div>
</template>
<template #error>
<div class="image-error">{{ error }}</div>
</template>
<div class="image-zoom-in" v-show="zoomInVisible">
<i class="el-icon-zoom-in"></i>
</div>
</el-image>
</template>
<script>
export default {
name: "ImageZoom",
props: {
src: {
type: String,
required: true,
},
fit: {
type: String,
default: "cover",
},
previewSrcList: {
type: Array,
default: () => [],
},
placeholder: {
type: String,
default: "加载中...",
},
error: {
type: String,
default: "加载失败",
},
},
data() {
return {
zoomInVisible: false,
};
},
methods: {
showZoomIn() {
this.zoomInVisible = true;
},
hideZoomIn() {
this.zoomInVisible = false;
},
},
};
</script>
<style scoped>
.image-zoom {
position: relative;
}
.image-placeholder,
.image-error {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: #ccc;
font-size: 14px;
}
.image-zoom-in {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 20px;
opacity: 0.6;
transition: opacity 0.3s;
}
.image-zoom-in:hover {
opacity: 1;
}
</style>
```
`VideoPlay` 组件实现了光标悬停出现播放按钮的视频组件功能,代码如下:
```vue
<template>
<div class="video-play" @mouseenter.native="showPlayButton" @mouseleave.native="hidePlayButton">
<el-video
:src="src"
:poster="poster"
:controls="false"
ref="video"
>
<div class="video-play-button" v-show="playButtonVisible" @click="play">
<i class="el-icon-caret-right"></i>
</div>
</el-video>
</div>
</template>
<script>
export default {
name: "VideoPlay",
props: {
src: {
type: String,
required: true,
},
poster: {
type: String,
required: true,
},
},
data() {
return {
playButtonVisible: false,
};
},
methods: {
showPlayButton() {
this.playButtonVisible = true;
},
hidePlayButton() {
this.playButtonVisible = false;
},
play() {
this.$refs.video.play();
},
},
};
</script>
<style scoped>
.video-play {
position: relative;
}
.video-play-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 50px;
opacity: 0.6;
transition: opacity 0.3s;
cursor: pointer;
}
.video-play-button:hover {
opacity: 1;
}
</style>
```
以上是一个简单的Vue前端页面示例,其中包含了三个常用的组件。需要注意的是,这里只提供了基本的功能实现,具体样式和交互效果可以根据自己的需求进行调整。
阅读全文