html - CSS自动隐藏/显示每2秒
问题描述
我想使用 css 隐藏和显示一个 div,例如:
显示 => 隐藏 => 显示 =>...
为此,我尝试了该代码:
#showMe {
animation: cssAnimation 0s 2s forwards;
visibility: hidden;
}
@keyframes cssAnimation {
to { visibility: visible;
}
}
但它只会隐藏它,请大家帮忙!!
解决方案
One way to do this is by adding keyframes for a specific progress (time-progress).
Some attributes in CSS are not animateable, so if you try to animate them they get instantly set to your "to" value, which is visible
. To work around this, we simply set the visibility to hidden
(in css) and keep it until 50% (in animation). At 51% we set it to visible
, where it gets instantly shown (until the end).
To make it "blinking" you can repeat this animation by appending infinite
which is a shorthand for animation-iteration-count: infinite
.
#showMe {
animation: cssAnimation 1s infinite;
visibility: hidden;
}
@keyframes cssAnimation {
50% {
visibility: hidden;
}
51% {
visibility: visible;
}
}
<div id="showMe">(╯°□°)╯︵ ┻━┻</div>
推荐阅读
- selenium-webdriver - sauceLabs 上的 webdriverIO 测试不适用于 Firefox
- r - Caret 包的置信区间
- moodle - Moodle 主页只有纯文本,没有主题
- php - echo php 正在转换为 ascii
- xsd - 创建一个支持 web.config 转换或多租户/配置 xml 文件之类的 XSD
- reactjs - 如何在 React 重新渲染中重用 DOM 节点?
- java - aws cognito 中的分页获取用户
- react-native - 在 React Native 中使用类和渲染 api 调用
- python - 如何在Pygame中画一个小角度低速闪烁的运动圆圈?
- amazon-web-services - 使用 Amazon Cognito 进行手动身份验证