css - 动画填充模式中断位置固定
问题描述
我有一个元素,它出现在带有淡入动画的页面中。单击元素时,元素会在整个页面上覆盖(类似于模态)。它在除 Firefox 之外的所有浏览器中都能正常工作。
删除animation-fill-mode: both
解决了这个问题,但我需要这个属性。
const element = document.getElementById('element');
let isClicked = false;
element.addEventListener('click', handleClick, false);
function handleClick() {
if (isClicked) {
element.classList.add('isVisible');
} else {
element.classList.remove('isVisible');
}
isClicked = !isClicked;
}
.element {
width: 200px;
height: 40px;
background: red;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
animation-delay: 100ms;
animation-timing-function: ease;
animation-duration: 200ms;
animation-name: fadeIn;
/* animation-fill-mode: both; */
}
.isVisible {
::after {
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: tomato;
z-index: -1;
animation-timing-function: ease;
animation-duration: 300ms;
animation-name: fadeIn;
}
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-100%);
}
to {
opacity: 1;
transform: translateY(0);
}
}
<div class="element" id="element">
<p>
element
</p>
</div>
解决方案
请为此添加动画延迟..它可能会起作用。
css
.element {
animation-delay: 1s;
}
推荐阅读
- c# - DSACryptoServiceProvider 有什么问题?
- ios - 仅在带有 RCTFata + 676 异常的 ios TestFlight 上发生 React-native App Crash
- python - 在 Azure Web 应用程序上部署 Python 时,远程意外结束
- scala - spark udf 中的异常处理
- javascript - JavaScript 变量没有 var 内部函数在全局执行上下文中不可用
- css - 如何根据 x 轴右侧的剩余宽度打开 React 组件
- python - 如何将时间列(小时和分钟)从数据类型“对象”转换为时间/日期时间类型?
- ruby-on-rails - ArgumentError - Api::V2 的副本已从模块树中删除,但仍处于活动状态!:
- r - Trouble in changing thickness of line segments in base plot
- azure-cosmosdb - 如何更改 cosmosDB 中的 API?