位置: IT常识 - 正文

Vue实现鼠标悬浮隐藏与显示图片效果 @mouseenter 和 @mouseleave事件(vue实现鼠标悬浮 显示全部内容)

编辑:rootadmin
Vue实现鼠标悬浮隐藏与显示图片效果 @mouseenter 和 @mouseleave事件 前言

推荐整理分享Vue实现鼠标悬浮隐藏与显示图片效果 @mouseenter 和 @mouseleave事件(vue实现鼠标悬浮 显示全部内容),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:vue实现鼠标悬浮 显示全部内容,vue鼠标悬浮切换图片,vue鼠标悬浮改变icon图标颜色,vue鼠标悬浮显示信息,vue鼠标悬浮文字上显示图片,vue鼠标悬浮切换图片,vue鼠标悬浮文字上显示图片,vue鼠标悬浮切换图片,内容如对您有帮助,希望把文章链接给更多的朋友!

前端vue 有个功能是鼠标移动到指定item上显示出来一个编辑和删除的图标 鼠标悬停在列表那么需要有悬浮显示的列表编辑和删除icon 文字不好描述,因为是web端录屏也比较麻烦 这里用截图说明

图片说明

功能实现

之前没做过这种效果,问了一下我的组长-豪哥 他告诉我很简单,利用vue的@mouseenter 和 @mouseleave事件就可以完美解决 本着这个思路,我去寻求答案,找了很多有关知识,自己也慢慢摸索 完成了该效果

下面说下实现 附代码

因为是在列表中完成的某个item的图标隐藏与显示 这个时候我们需要合index绑定 并且和改条目的id绑定(用来互斥)

这里需要注意一点Vue实现鼠标悬浮隐藏与显示图片效果 @mouseenter 和 @mouseleave事件(vue实现鼠标悬浮 显示全部内容)

@mouseenter 和 @mouseleave 方法必须放到父类的div中 才能起效果

我们需要 在js中把id绑定 把index设置值,默认为false 既不显示 下面js代码中做了id绑定和给数组的标记赋值的关系

/** *左边图表控制隐藏与显示 */const leftIcon = reactive({ inputAry: [] as boolean[]})const leftIconId = ref()const mouseenter = (index: number, item: SymptomList) => { leftIcon.inputAry[index] = true leftIconId.value = item.id console.log('mouseenter')}const mouseleave = (index: number, item: SymptomList) => { leftIcon.inputAry[index] = false leftIconId.value = item.id; console.log('mouseleave')}

我们在html中把@mouseenter 和 @mouseleave事件添加 然后再指定的div标签内 做隐藏与显示的判断 还是根据id和当前点击的标记位

<div v-for="(item, index) in symptomList" class="item"> <div class="left"> <!-- @mouseenter="mouseenter(index,item)" 在这里绑定index和item数据类(这里有我们要的数据id)--> <div class="left-div" @mouseenter="mouseenter(index,item)" @mouseleave="mouseleave(index,item)"> <div v-if="editShow.inputAry[index] == true && item.id == diseaseId "> <a-input class="input" v-model:value="inputContent" autofocus="autofocus" :max-length="10" @change="changeInput()" /> <a-button class="commit" @click="handleInputCommit(item,index)"> <template #icon> <check-outlined style="color: #ffffff" /> </template> </a-button> <a-button class="cancel" @click="handleInputCancel(index)"> <template #icon> <close-outlined /> </template> </a-button> </div> <div v-else style="display: flex;"> <div>{{ item.name }}</div> <div class="right-icon" <!-- 这里是item尾部的2个图标 编辑和删除图标 我们做了2个判断 第一是==true时,我们才把图标显示出来 第二:将当前点击的id记录 --> v-if="leftIcon.inputAry[index] == true && item.id == leftIconId"> <a-button style="color:#676E7C; width: 13.7px ; height: 13.7px;" @click="handleClickEdit(item,index)" type="link"> <template #icon> <edit-outlined /> </template> </a-button> <a-button style="margin-left: 5px; color:#676E7C; width: 13.7px ; height:13.7px;" @click="handleClickDel(item,index)" type="link"> <template #icon> <delete-outlined /> </template> </a-button> </div> </div> </div> </div>mouseover 和 mouseenter 的区别

mouseover:当鼠标移入元素或其子元素都会触发事件,有一个重复触发,事件叠加过程。对应的移除事件是 mouseout

mouseenter:当鼠标移入元素本身(不包含元素的子元素)会触发事件,事件不会叠加。对应的移除事件是 mouseleave

hover 事件调用顺序:

mouseover -> mouseenter -> mousemove(hover进去之后移动会触发) -> mouseout -> mouseleave

用div来演示所有事件方法

<div <!-- 1、进入元素 事件会叠加 --> @mouseover="mouseover" <!-- 2、进入元素 事件不叠加 --> @mouseenter="mouseenter" <!-- 3、移动 --> @mousemove="mousemove" <!-- 4、离开元素 事件会叠加--> @mouseout="mouseout" <!-- 5、离开元素 事件不叠加 --> @mouseleave="mouseleave" <!-- 6、鼠标在元素上 按下 --> @mousedown="mousedown" <!-- 7、鼠标在元素上 抬起 --> @mouseup="mouseup" > </div>总结

学习之路 永无止步 记录当下,保持一颗向上的心态~!

本文链接地址:https://www.jiuchutong.com/zhishi/289753.html 转载请保留说明!

上一篇:Calanques de Piana岩层上的一个心形洞,法国科西嘉岛 (© joningall/Getty Images)

下一篇:阳光照耀下的火山岩山脊,冰岛埃亚菲亚德拉冰盖 (© Erlend Haarberg/Minden Pictures)(阳光照耀下的人)

  • airpods3支持主动降噪吗(airpods2支持主动降噪吗)

  • 微信接收的文件在手机上的位置(微信接收的文件怎么彻底删除)

  • 海尔洗衣机err7什么故障(海尔洗衣机err7故障处理图解)

  • 虚拟内存有什么用(虚拟内存有什么缺点)

  • 创维t2和t2pro的区别(创维t2评测)

  • 怎么关闭支付宝刷脸(怎么关闭支付宝刷脸支付功能)

  • 新客首单红包用不了(为什么新客首单红包用不了)

  • 淘宝聊天消息显示感叹号(淘宝聊天消息显示今日在线什么意思)

  • 华为变焦100倍手机是什么型号(华为100倍变焦不清楚)

  • 微信不是好友可以发出信息吗(微信不是好友可以点赞吗)

  • 此快捷方式引用的项目无法访问(此快捷方式引用的无法访问没有权限)

  • 快手验证手机号不用了怎么办(快手手机号怎么验证)

  • 华为nova7怎么插耳机(华为nova7怎么插卡图解教程)

  • 防窥屏膜伤眼睛嘛(防窥屏膜的原理)

  • 为什么修改不了实名认证(qq昵称为什么修改不了)

  • iphone11支不支持5g网络(iPhone11支不支持口罩解锁)

  • 红米2016101是什么型号(红米手机型号2016112)

  • ids与ips主要区别(ids和ips设备位于网络中的什么位置)

  • 支付宝怎么解绑实名制(支付宝怎么解绑生活缴费用户)

  • 华为mate20pro指纹解锁在哪里(华为mate20pro指纹设置不见了)

  • 苹果手机地点相册封面怎么删除(苹果手机地点相簿怎么删掉)

  • 淘宝新人专享红包为什么用不了(淘宝新人专享红包怎么取消)

  • 企鹅fm下载的文件在哪(企鹅fm下载的文件找不到)

  • qq收到的礼物在哪里看(qq收到的礼物在哪里展示)

  • 如何复制指纹(如何复制指纹锁的指纹?)

  • 火山视频怎么做音乐(火山视频怎么做任务赚金币)

  • 电话录音在哪找(荣耀手机打电话录音在哪找)

  • 王者荣耀中刘邦怎么出装?(王者荣耀中刘邦技能解析以及如何连招)

  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设 电脑维修 湖南楚通运网络