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

vue+elementUI+transition实现鼠标滑过div展开内容,鼠标划出收起内容,加防抖功能

文章目录

  • 一、场景
  • 二、实现代码
    • 1.子组件代码结构
    • 2.父组件


一、场景

这两天做项目,此产品提出需求 要求详情页的顶部区域要在鼠标划入后展开里面的内容,鼠标划出要收起部分内容,详情底部的内容高度要自适应,我这里运用了鼠标事件+transition实现,加上lodash debounce进行防抖,下面是具体实现代码

二、实现代码

1.子组件代码结构

代码如下(示例):

<template><divclass="project-header"@mouseenter="enterFun()"@mouseleave="leaveFun()"ref="project-header"><div class="project-header-top">顶部要显示的部分</div><div class="bottom" v-show="showProjectHeaderBottom">顶部要隐藏的部分,鼠标划入显示</div></div>
</template><script>
import { debounce } from 'lodash';//npm install lodash引入
export default {name: '',components: {},props: {},data() {return {showProjectHeaderBottom: false,//控制顶部要隐藏的显隐};},methods: {// 鼠标滑过enterFun:debounce(function(){this.showProjectHeaderBottom = true;this.$emit('getHeight', 'hover');},100),// 鼠标划出leaveFun:debounce(function(){this.showProjectHeaderBottom = false;this.$emit('getHeight', null);},100),},
};
</script>
<style lang="scss" scoped>
.project-header {height: 68px;
}
</style>

2.父组件

代码如下(示例):

<template><div class="project-detail" ref="project-browse" ><Headerref="project-detail-top"class="project-detail-top"@getHeight="getHeight"></Header><div class="tab-content" style="position: relative" ref="tab-content"></div></div>
</template><script>
import Header from './components/detailHeader.vue';
export default {name: '',components: {  Header},props: {},data() {},methods: {mountedInit() {this.getHeaderheight();window.addEventListener('resize', this.getHeaderheight);},getHeaderheight(type) {this.$nextTick(() => {let projectHeader = type === 'hover' ? 208 : 60;document.querySelector('.tab-content .el-tabs__content').style.overflow = type === 'hover' ? 'hidden' : 'auto';let height = this.$refs['project-browse']?.offsetHeight - projectHeader;this.$refs['tab-content'].style.height = height + 'px';//自适应this.$refs["project-detail-top"].$el.style.height=projectHeader+ 'px';});},},created() {this.createdInit();},mounted() {this.mountedInit();},
};
</script>
<style lang="scss" scoped>
.project-detail-top {transition: height 0.2s ease-in-out;overflow: hidden;
}
</style>

http://www.lryc.cn/news/500933.html

相关文章:

  • 大模型语料库的构建过程 包括知识图谱构建 垂直知识图谱构建 输入到sql构建 输入到cypher构建 通过智能体管理数据生产组件
  • 阿里云ECS服务器域名解析
  • 牛客周赛71:A:JAVA
  • 查询产品所涉及的表有(product、product_admin_mapping)
  • 算法基础学习Day5(双指针、动态窗口)
  • docker 部署 mysql 9.0.1
  • 关于小标join大表,操作不当会导致笛卡尔积,数据倾斜
  • SpringMVC全局异常处理
  • 出海服务器可以用国内云防护吗
  • 从零开始的使用SpringBoot和WebSocket打造实时共享文档应用
  • Ant Design Pro实战--day01
  • pcl点云库离线版本构建
  • 字节高频算法面试题:小于 n 的最大数
  • ElasticSearch常见面试题汇总
  • Spring Boot如何实现防盗链
  • 工作中常用springboot启动后执行的方法
  • 力扣-图论-3【算法学习day.53】
  • Linux上的C语言编程实践
  • 芝法酱学习笔记(1.3)——SpringBoot+mybatis plus+atomikos实现多数据源事务
  • 【计算机网络】实验12:网际控制报文协议ICMP的应用
  • 收缩 tempdb 数据库
  • kubesphere搭建 postgres15
  • 解决npm问题用到的资源,错误原因和方法
  • 【uni-app 微信小程序】新版本发布提示用户进行更新
  • Redis性能优化18招
  • ElasticSearch 与向量数据库的结合实践:突破亿级大表查询瓶颈20241204
  • C#实现一个HttpClient集成通义千问-流式输出内容提取
  • 微信小程序后台搭建—node+mysql
  • 断点续传+测试方法完整示例
  • C# 中的静态构造函数和实例构造函数的区别