我知道我不能display
none
和block
之間轉換,但我認爲我可以做一些跨動畫由這樣做:是否使用關鍵幀顯示CSS屬性的動畫效果?
li:nth-child(1) {
-webkit-animation: winkle 1s linear;
animation: winkle 1s linear;
}
li:nth-child(2) {
-webkit-animation: winkle 1s linear 1s;
animation: winkle 1s linear 1s;
}
li:nth-child(3) {
-webkit-animation: winkle 1s linear 2s;
animation: winkle 1s linear 2s;
}
li:nth-child(4) {
-webkit-animation: winkle 1s linear 3s;
animation: winkle 1s linear 3s;
}
li:nth-child(5) {
-webkit-animation: winkle 1s linear 4s;
animation: winkle 1s linear 4s;
}
@-webkit-keyframes winkle {
0%, 100% {
display: none;
}
1%,
99% {
display: block
}
}
@keyframes winkle {
0%, 100% {
display: none;
}
1%,
99% {
display: block
}
}
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
但實際上這是不工作。你能證實這是不可能的嗎?還有其他解決方案嗎?我想到了這一點,但它也不起作用。如果你能想出更好的東西,將不勝感激。
li:nth-child(1) {
-webkit-animation: winkle 1s linear;
animation: winkle 1s linear;
}
li:nth-child(2) {
-webkit-animation: winkle 1s linear 1s;
animation: winkle 1s linear 1s;
}
li:nth-child(3) {
-webkit-animation: winkle 1s linear 2s;
animation: winkle 1s linear 2s;
}
li:nth-child(4) {
-webkit-animation: winkle 1s linear 3s;
animation: winkle 1s linear 3s;
}
li:nth-child(5) {
-webkit-animation: winkle 1s linear 4s;
animation: winkle 1s linear 4s;
}
li {
overflow: hidden;
}
@-webkit-keyframes winkle {
0%, 100% {
height: 0;
color: red;
}
1%,
99% {
height: auto;
color: blue;
}
}
@keyframes winkle {
0%, 100% {
height: 0;
color: red;
}
1%,
99% {
height: auto;
color: blue;
}
}
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
高度呢?高度是可以動畫的! – Vandervals
可以將高度設置爲動畫(固定值,不自動),但不顯示。 – Quentin
但在第二個例子中,它也不起作用! – Vandervals