html - 元素动画时间未按预期使用 CSS 加载/启动
问题描述
我想使用仅使用 CSS 将用户悬停在其中的一小部分时出现的元素制作一个弹出页脚。我在 jsfiddle 上运行代码并且它正在工作。
不幸的是,当我在 google 版本 88.0.4(使用 Visual Studio 代码)上从 localhost 运行它时,我可以清楚地看到元素属性没有按时加载。它们的生成速度太慢。转换确实有效,问题仅在刷新/加载页面后发生。
这是代码: https ://jsfiddle.net/hzvgcw58/4/
这是视频: https ://youtu.be/hiNX-e9uHWA
当我刷新页面时,问题发生在 00:02 到 00:06
如何解决这个问题?
.tab-container {
position: relative;
height: 200px;
width: 870px;
margin: auto;
overflow: hidden;
background-color: rgba(255, 247, 234, 0.95);
}
.tab {
position: relative;
bottom: -153px;
height: 47px;
width: 182px;
z-index: 9;
border-radius: 15px 15px 0px 0px;
background-color: none;
opacity: 0.5;
transition: 2s ease-in-out;
}
.tab::after {
width: 870px;
height: 113px;
background-color: none;
position: absolute;
bottom: -112px;
left: 0px;
content: '';
z-index: 3;
}
.a {
position: absolute;
bottom: 0;
left: 0;
z-index: 3;
width: 150px;
height: 19px;
background-color: rgba(54, 52, 49, 1);
border-radius: 15px 15px 0px 0px;
padding: 14px 16px;
font-size: 17px;
transition: 2s ease-in-out;
}
.b {
background-color: rgba(54, 52, 49, 1);
position: absolute;
bottom: -113px;
z-index: 3;
padding: 6px 0px;
height: 101px;
width: 870px;
transition: 2s ease-in-out;
}
/* Change background color of buttons on hover */
.tab:hover {
bottom: -40px;
transition: 2s ease-in-out;
}
.tab:hover + .a {
cursor: pointer;
transition: 2s ease-in-out;
bottom: 112px;
display: block;
}
.tab:hover ~ .b {
cursor: pointer;
transition: 2s ease-in-out;
display: block;
bottom: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<div class="footer-container">
<div class="footer">
<div class="tab-container">
<div class="tab">
</div>
<div class="a">
London
</div>
<div class="b">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
</div>
</div>
</div>
</body>
</html>
编辑:感谢@rauberdaniel,代码终于被修复了。我删除了一些不必要的属性,例如transition: 2s ease-in-out;
& display: block;
in .tab:hover + .a {
,并更改了html中的一些代码
解决方案
更改您的transition
属性以仅包含您要转换的值(在本例中bottom
),例如:
.tab:hover {
transition: bottom 2s ease-in-out;
}
请注意,转换位置值(如top
or bottom
)通常不是一个好主意,因为它会为浏览器触发大量昂贵的布局任务。相反,您应该使用transform: translate(…)
以向上移动页脚。
推荐阅读
- python - 使用变量选择 numpy 数组中的特定或所有维度
- python - 在python中用逗号写csv作为小数分隔符
- python - Datetime 和 suntime,TypeError:不能减去 offset-naive 和 offset-aware datetimes
- spring - Spring 集成持续监控通道消息是否满足条件
- php - 两个外观相同的 MySQL 列显然包含不同的字符
- docker - 一台服务器上的远程容器工作,另一台不工作
- html - 对齐div左上角的圆形图像
- matomo - Matomo - 获取用户和上次访问
- python - 使用 Pytest,我找不到同时运行 2 个测试类的方法,而每个类都有多个测试?
- post - centos7中的Apache http客户端(发布请求)大小限制问题