当前位置: 首页 > news >正文

【大前端vue:组件】鼠标上移 出现动画

【大前端vue:组件】鼠标上移 出现动画

在这里插入图片描述

<template><div class="view-introduction-culture"><div class="culture-wrapper"><h2 class="culture-title">鼠标上移:展示动画 显示出来</h2><div class="culture-content"><div v-for="(item, index) in cultureList" :key="index" class="culture-item"@mouseenter="handleMouseEnter(index)" @mouseleave="handleMouseLeave(index)"><!-- 背景图片层 --><div class="item-bg" :style="{ backgroundImage: `url(${item.bgImage})` }"><div class="item-number">{{ item.number }}</div><div class="item-name">{{ item.name }}</div><div class="item-icon"><img :src="item.icon" :alt="item.name"></div></div><!-- 悬浮展示层 --><div class="hover-content" :class="{ active: activeIndex === index }"><div class="hover-text">{{ item.description }}</div></div></div></div></div></div>
</template><script>
export default {name: 'CultureIndex',data() {return {activeIndex: null, // 当前激活的索引hoverTimer: null, // 用于存储定时器cultureList: [{number: '01',name: '标签1',icon: '/icons/culture-1.png',bgImage: '/images/culture-bg-1.jpg',description: '标签描述文字'},{number: '02',name: '标签2',icon: '/icons/culture-2.png',bgImage: '/images/culture-bg-2.jpg',description: '标签描述文字'},{number: '03',name: '标签3',icon: '/icons/culture-3.png',bgImage: '/images/culture-bg-3.jpg',description: '标签描述文字'},{number: '04',name: '标签4',icon: '/icons/culture-4.png',bgImage: '/images/culture-bg-4.jpg',description: '标签4描述文字'}]}},methods: {handleMouseEnter(index) {// 清除之前的定时器if (this.hoverTimer) {clearTimeout(this.hoverTimer)}// 设置新的定时器this.hoverTimer = setTimeout(() => {this.activeIndex = index}, 300)},handleMouseLeave(index) {// 清除定时器if (this.hoverTimer) {clearTimeout(this.hoverTimer)this.hoverTimer = null}// 只有当前激活的项目是当前离开的项目时,才清除激活状态if (this.activeIndex === index) {this.activeIndex = null}}},// 组件销毁时清理定时器beforeDestroy() {if (this.hoverTimer) {clearTimeout(this.hoverTimer)}}
}
</script><style lang="scss">.view-introduction-culture {width: 100%;background: {image: url('@/assets/image/introduction/bg.png') no-repeat center center;size: 100% 100%;color: #F1F6FF;}padding: 70px 0;.culture-wrapper {width: 1200px;margin: 0 auto;}.culture-title {text-align: center;font-size: 28px;color: #333;margin-bottom: 51px;}.culture-content {display: flex;justify-content: space-between;}.culture-item {position: relative;width: 302px;height: 300px;overflow: hidden;cursor: pointer;.item-bg {width: 100%;height: 100%;background: {size: cover;position: center;}position: relative;display: flex;flex-direction: column;align-items: center;justify-content: center;color: #fff;padding: 20px;&::after {content: '';position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: linear-gradient(to bottom, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.6));}}.item-number,.item-name,.item-icon {position: relative;z-index: 1;}.item-number {font-size: 36px;font-weight: bold;margin-bottom: 10px;}.item-name {font-size: 24px;margin: 10px 0;}.item-icon {margin-top: 20px;img {width: 40px;height: 40px;}}.hover-content {position: absolute;top: 0;left: 0;width: 302px;height: 500px;background: pink;opacity: 0;display: flex;align-items: center;justify-content: center;transition: opacity 0.1s ease;padding: 30px;pointer-events: none; // 防止悬浮层影响鼠标事件&.active {opacity: 0.8;}.hover-text {color: #fff;font-size: 16px;line-height: 1.8;text-align: center;}}}
}
</style></style>

http://www.mrgr.cn/news/80004.html

相关文章:

  • pyfink1.20版本下实现消费kafka中数据并实时计算
  • 【架构】从 Socket 的角度认识非阻塞模型
  • xshell连接虚拟机,更换网络模式:NAT->桥接模式
  • 网络基础 - TCP/IP 五层模型
  • 爬虫基础知识点
  • 设计模式——Singleton(单例)设计模式
  • 12.12 深度学习-注意力机制
  • Java从入门到工作3 - 框架/工具
  • 如何在项目中使用人大金仓替换mysql
  • 单目深度估计模型 lite-mono 测试
  • 如何使用程序查询域名whois信息?(带PHP/C#示例)
  • all/any函数可以对“条件”打包(Python)
  • 解决VSCode无法识别相对路径的问题
  • 使用 mkcert 工具自签发 https 证书并进行本地受信
  • es 3期 第15节-词项查询与跨度查询实战运用
  • chattts生成的音频与字幕修改完善,每段字幕对应不同颜色的视频,准备下一步插入视频。
  • ArcGIS MultiPatch数据转换Obj数据
  • 优秀前端文章笔记----持续更新(20241211-至今)
  • YashanDB 23.2 YAC 共享集群部署和使用自带YMP迁移工具进行数据迁移,效果很city
  • 麒麟系统+达梦数据库+MybatisPlus+Redis+SpringBoot