位置: IT常识 - 正文

【Vue】悬浮窗和聚焦登录组件经验总结(vue鼠标悬浮菜单)

编辑:rootadmin
【Vue】悬浮窗和聚焦登录组件经验总结 前言

推荐整理分享【Vue】悬浮窗和聚焦登录组件经验总结(vue鼠标悬浮菜单),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:vue浮层,vue中鼠标悬浮事件函数,vue悬浮窗口,vue拖动悬浮按钮,vue鼠标悬停并以悬浮框显示,vue 浮动窗口,vue鼠标悬浮菜单,vue悬浮窗口,内容如对您有帮助,希望把文章链接给更多的朋友!

​ 本文整理了实现悬浮窗以及聚焦登录组件的功能。

​ 为的是方便大家和自己的学习。

​ 省流:可以只看1.2 和 2的代码即可

1 悬浮窗

现在各大流行视频网站的平台都在使用这种悬浮显示的效果,我就想这种东西是怎样搞出来的呢!几经尝试,终于找到了一个实现方式,记录一下自己的开发历程,方便以后的使用,也为了各C友提供便利。

1.1 使用display

尝试用display实现,利用display:none和block的切换,来实现悬浮窗的显示/关闭。

把方法加在div1(悬浮窗)、div2(带图片背景的组件)共同的父组件div上,这样可以实现悬浮窗的效果

<template> <div class="div1" @mousemove="showDiv1()" @mouseout="hideDiv1()"> <div class="div_header"> 我是悬浮框 </div> <div class="div_main" id="div_main"> </div> </div></template><script>export default { name: 'Header', methods:{ showDiv1(){ var d1 = document.getElementById('div_main'); d1.style.cssText = 'display:block;' }, hideDiv1() { var d1 = document.getElementById('div_main'); d1.style.cssText = 'display:none;' } }}</script><style scoped>.div1 { height: 50px; width: 300px; border: 1px solid; position: fixed; top: 0px; right: 100px; cursor: pointer;}.div_header { width: 300px; height: 50px; /* border: 1px solid; */ line-height: 50px; text-align: center; background-color: #8EC5FC; background-image: linear-gradient(62deg, #8EC5FC 0%, #E0C3FC 100%);}.div_main{ height: 400px; width: 300px; /* margin-top: 10px; */ background-image: url('@/assets/十元.png'); background-size: 300px 400px; display: none;}</style>

但是一旦两者之间有了间隙,这样的效果,就不太好了。这要求你必须有一定的手速,才能实现想要的效果

而且这不符合流行网站的形式,因为在鼠标移出图标的时候,他总是有一个"缓冲"效果,延时片刻,再消失。

这里很容易想到要用动画的形式,但当我添加了动画效果之后,意外的发现动画的效果无效。在CSDN上搜索了一下,发现display是不能和动画一块使用的,否则就会无效。

【Vue】悬浮窗和聚焦登录组件经验总结(vue鼠标悬浮菜单)

所以即使这里写了动画,也是不生效的

利用动画解决不生效

<template> <div class="div1" @mousemove="showDiv1()" @mouseout="hideDiv1()"> <div class="div_header"> 我是悬浮框 </div> <div class="div_main" id="div_main"> </div> </div></template><script>export default { name: 'Header', methods:{ showDiv1(){ var d1 = document.getElementById('div_main'); d1.style.cssText = 'display:block;' }, hideDiv1() { var d1 = document.getElementById('div_main'); d1.style.cssText='animation-name:example; animation-duration:1s;animation-fill-mode: forwards;'; } }}</script><style> @keyframes example{ from{ display: block; } to{ display: none; } }</style><style scoped>.div1 { height: 50px; width: 300px; border: 1px solid; position: fixed; top: 0px; right: 100px; cursor: pointer;}.div_header { width: 300px; height: 50px; /* border: 1px solid; */ line-height: 50px; text-align: center; background-color: #8EC5FC; background-image: linear-gradient(62deg, #8EC5FC 0%, #E0C3FC 100%);}.div_main{ height: 400px; width: 300px; margin-top: 10px; background-image: url('@/assets/十元.png'); background-size: 300px 400px; display: none;}</style>1.2 使用visibility(☆)

将display:none 改为 visibility: hidden,将display: block;改为visibility: visible;

这样是可以实现的,这里我特意把消失的时间放长了一下

这是正常的效果

<template> <div class="div1" @mousemove="showDiv1()" @mouseout="hideDiv1()"> <div class="div_header"> 我是悬浮框 </div> <div class="div_main" id="div_main"> </div> </div></template><script>export default { name: 'Header', methods:{ showDiv1(){ var d1 = document.getElementById('div_main'); d1.style.cssText = 'visibility: visible;' }, hideDiv1() { var d1 = document.getElementById('div_main'); d1.style.cssText='animation-name:example; animation-duration:0.1s;animation-fill-mode: forwards;'; } }}</script><style> @keyframes example{ from{ visibility: visible; } to{ visibility: hidden; } }</style><style scoped>.div1 { height: 50px; width: 300px; border: 1px solid; position: fixed; top: 0px; right: 100px; cursor: pointer;}.div_header { width: 300px; height: 50px; /* border: 1px solid; */ line-height: 50px; text-align: center; background-color: #8EC5FC; background-image: linear-gradient(62deg, #8EC5FC 0%, #E0C3FC 100%);}.div_main{ height: 400px; width: 300px; margin-top: 10px; background-image: url('@/assets/十元.png'); background-size: 300px 400px; /* display: none; */ visibility: hidden;}</style>

说来很奇怪,我在实战的时候,将位置设置为position:fixed;明明不可以,后来换成absolute就可以了,但是再写这篇博客的时候,换成fixed也是可以的,原来使用的地方,居然也莫名其妙用fixed可以了,有些莫名其妙。

2 全屏只能点击登录组件

原理

有一个空的div(宽高为0),z-index的等级大于所有的标签(除了登录页面),点击登录按钮的时候,设置div的宽高覆盖整个页面,同时显示出登录界面,这时候除了登录页面其他的组件都不能被点击,因为其他的组件都被这个空的div覆盖了。

刚开始的页面是这样的

当点击登录按钮的时候,让用于隐藏组件具有整个屏幕的宽高,从而覆盖怎么屏幕,同时让登录组件展示,因为登录组件的层级大于用于隐藏的组件,所有用于隐藏的组件覆盖了除登录组件的所有的组件,这也就也解释了为什么只有登录组件可以使用。

关闭:想要关闭的时候,在利用一个函数,设置为不显示即可,display:none;

代码<template> <div> <div class="div1"> <div class="div_header" @click="showDiv1()"> 登录/注册 </div> <div class="button_main"> <button style="cursor: pointer;">点我</button> <button style=" cursor: pointer;">点我</button> </div> </div> <div class="login_main" id="login_main"> 用户名:<input type="text" placeholder="用户名" /> <br> 密&nbsp;&nbsp;码: <input type="password" placeholder="密码"> </div> <div class="hide_main" id="hide_main"></div> </div></template><script>export default { name: 'HelloWorld', methods: { showDiv1() { var d1 = document.getElementById('login_main'); var d2 = document.getElementById('hide_main'); d2.style.height = "100vh"; d2.style.width = "100%"; d2.style.display = "block"; d1.style.cssText = 'display:block' }, }}</script><style scoped>.div1 { height: 50px; width: 300px; border: 1px solid; position: fixed; top: 0px; right: 100px; cursor: pointer;}.div_header { width: 300px; height: 50px; /* border: 1px solid; */ line-height: 50px; text-align: center; background-color: #8EC5FC; background-image: linear-gradient(62deg, #8EC5FC 0%, #E0C3FC 100%);}.login_main { width: 500px; height: 400px; display: none; background-color: aquamarine; position: fixed; top: 100px; left: 500px; z-index:1050;}.hide_main { border: solid 3px green; /* background: #000; */ position: fixed; display: none; top: 0; z-index: 1040;}.button_main { position: fixed; width: 100px; height: 200px; top: 100px; left: 50px;}</style>
本文链接地址:https://www.jiuchutong.com/zhishi/300558.html 转载请保留说明!

上一篇:Diffusion models代码实战:从零搭建自己的扩散模型

下一篇:学习 Python 之 Pygame 开发魂斗罗(十)(python 如何学)

  • 加工企业税收优惠政策
  • 减去税率怎么算
  • 月初领票后还能作废申报吗
  • 注册资本印花税按年申报还是按次申报
  • 转正后个税增加
  • 流动负债和长期负债的比例多少合适
  • 企业所得税可以不交吗
  • 股权资本成本包括什么
  • 维修 物业
  • 税务迁移会影响外经证核销吗
  • 税务登记时要财务确认吗
  • 互联网企业交什么保险
  • 广告喷绘增值税怎么算
  • 对公账户钱怎么退回去
  • 请问给员工报销怎么报
  • 房产转让的房产税怎么算
  • 分公司税率怎样确定
  • 小规模所得税表格模板
  • 委托加工物资的加工费计入什么科目
  • win10 批量安装软件
  • 苹果电脑优酷视频打不开
  • linux怎么用gcc编译c程序
  • 对视同销售行为应如何进行税务处理
  • 业务招待费会计分录
  • 二手固定资产怎么折旧
  • 多开票金额会计分录
  • 停产企业税收申请减免
  • 任意盈余公积金的用途
  • 增值税留抵退税怎么操作
  • 小规模纳税人缴税的分录
  • 先收票后收货
  • 建筑业异地预缴增值税
  • 模式识别与图像处理能做什么
  • ChatGPT 能自己跑代码了!
  • 事业单位无形资产折旧是当月还是下月
  • etc电子发票需要多久才能开
  • 一年内到期的非流动资产包括
  • 企业贷款利息可以开发票吗
  • 帝国cms移动端
  • 固定资产盘亏是管理费用吗
  • 民办非企业免税政策
  • 捐赠支出汇算清缴需要调增吗
  • 为什么盈利要利息呢
  • 哪些情况可以开立基本账户
  • 融资租赁的增值税专用发票可不可以抵扣
  • 白条抵库现象
  • 不动产在建工程领用原材料进项税额可以抵扣吗
  • 对外公司
  • 其他应付款做账
  • 员工借款属于什么现金流量
  • 个人工资税收怎么计算年收入
  • 税收滞纳金什么意思
  • 进项税转出年底怎么结转
  • 营业外收入的核算内容
  • 冲销管理费用如何做分录
  • 待处理财产损溢借贷增减方向
  • 因质量问题质保金未能收回怎么处理
  • 上月计提少了怎么办
  • 建安发票是增值税发票吗
  • 应收账款平均余额公式
  • 企业投资所得如何征税
  • 出售固定资产属于什么收入
  • 工业企业营业税率
  • mysql建唯一索引
  • 盗版win10系统
  • centos7 阿里云 yum
  • window打开注册表
  • win10 预览版变正式版
  • centos 安装chia
  • mac的mail登不上
  • windows7的安装步骤
  • FIF互动帮助手册系列-HTML手册 flash版
  • unity商店资源在unity中打开
  • 带你了解处女座
  • js中dom的用法
  • android开源app
  • 本市可以跨县高考报名吗
  • 爱普生如何
  • 如何在电子税务局变更财务负责人
  • 宣传中常用的效应包括
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设