【发布时间】:2022-02-10 05:11:56
【问题描述】:
我有一个按钮,点击时会显示一个 <p> text <p/> 元素,我给了它一个动画(从上到下),但现在我创建了另一个按钮,点击后将删除 <p> 元素中的文本想在发生这种情况时添加动画,但是当我编写 CSS 以在删除时为文本设置动画时,它似乎会覆盖之前的动画。
CSS 中是否有 if else 语句,或者我可以在 JavaScript 中使用它吗? 这是普通的 JavaScript 和 CSS。
<button class="button" onclick="Click()">click me</button>
<p id="appear" hidden>This text should appear on click</p>
<button class="butremove" onclick="ClickRemove()">click me to delete message</button>
@keyframes buttonappear {
0% {top: 10px;}
100% {top: 175px;}
}
#appear {
position: absolute;
top: 175px;
animation-name: buttonappear;
animation-duration: 2.5s;
}
const Click = () => {
document.getElementById("appear").style.display = "block";
}
const ClickRemove = () => {
document.getElementById("appear").style.display = "none";
}
我可以使用什么 CSS 或 JS 代码在文本消失而不覆盖之前的动画时为其设置动画?
【问题讨论】:
标签: html css css-animations