javascript - 鼠标悬停时滑出 div 标签
问题描述
我正在尝试创建一个动画,让 div 在鼠标悬停时滑出,并保持滑出直到鼠标移出。实现这一目标的最佳方法是什么?抱歉,我是 React 新手。这是我的通用代码。抱歉格式不好。
return (
<div id="homeDiv">
<div>
<Navbar />
</div>
<div className="portStyle">
</div>
<div className="cvStyle1">
</div>
<div className="nameStyle">
<h1 >Lin</h1>
<h1 >Edmund</h1>
</div>
</div>
)
和相关的CSS:
#homeDiv {
overflow-y: hidden;
overflow-x:hidden;
}
.nameStyle {
height: 100vh;
width: 30%;
display: flex;
justify-content: flex-end;
flex-direction: column;
}
.portStyle {
height: 100vh;
width: 20%;
position: relative;
float: right;
background-color: #000;
}
.cvStyle1 {
height: 100vh;
width: 20%;
position: relative;
float: right;
background-color: #ccc;
}
不确定我是否应该使用 CSS 动画或者是否应该为此使用 React 动画,因为我知道 CSS 不支持 onMouseOver,除非有一些解决方法。Navbar 元素只是我对齐到屏幕右侧的导航栏,宽度为 20%,高度为 100vh。
解决方案
你在寻找这样的东西吗?
.container {
position: relative;
width: 70%;
}
.image {
width: 100%;
}
.overlay {
position: absolute;
bottom: 0;
left: 100%;
right: 0;
background-color: darkcyan;
overflow: hidden;
width: 0;
height: 100%;
transition: .5s ease;
}
.container:hover .overlay {
width: 100%;
left: 0;
}
.text {
color: white;
font-size: 20px;
position: absolute;
padding: 10px;
white-space: wrap;
}
<div class="container">
<img src="https://pixlr.com/photo/image-design-11-1-pw.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
</div>
</div>
推荐阅读
- python - Python:在字典项中引用不同的字典项
- vb.net - 我应该避免错误“变量'foo'在被赋值之前被使用。'?
- electron - 如何为 Wayland 运行电子应用程序?
- angular - Angular bypassSecurityTrustResourceUrl 没有按预期工作
- angular - 如何使用 NgIdleKeepaliveModule 在构造函数中防止登录组件中的会话超时
- javascript - Node js - 如果记录已经存在,则添加序号后缀
- python - 将时间戳字符串日期转换为日期时间 python
- amcharts - AmCharts - XYChart - 最小柱高度
- c# - DevExpress:网格视图图像;如何调整图像大小以适合单元格的大小
- javascript - 为什么 Github gist API 会抛出 400 错误?