【发布时间】:2020-10-01 20:57:43
【问题描述】:
您好,我正在尝试反转详细信息和摘要的动画。当详细信息打开时,我可以制作动画,当我再次单击时没有反向动画。再次单击摘要时如何使动画正常工作?谢谢你。 这是我的 HTML 代码和 CSS
HTML
<details>
<summary>I am awesome</summary>
<p>Hi there this is an awesome paragraph</p>
</details>
CSS
html {
height: 100vh;
}
body {
height: 100%;
display: grid;
place-content: center;
font-family: 'Montserrat', sans-serif;
}
details {
background: mistyrose;
padding: 4em;
width: 20rem;
}
details:not(open) summary~* {
animation: anim-rev .5s ease-in;
}
details[open] summary~* {
animation: anim .5s ease-in;
}
@keyframes anim {
0% {
opacity: 0;
margin-top: -50px;
}
100% {
opacity: 1;
margin-left: 0;
}
}
@keyframes anim-rev {
0% {
opacity: 1;
margin-left: 0;
}
100% {
opacity: 0;
margin-top: -50px;
}
}
【问题讨论】:
-
@alotropico 这不是我正在寻找的答案。你试过我的代码吗?当 details 具有 open 属性时,我的代码能够设置动画。我正在寻找的是在再次单击详细信息时反转动画
标签: html css css-animations css-transitions