我为此使用 csstransition-delay
属性,并使用 scss 为每个<li>
元素增加它
https://www.w3schools.com/cssref/css3_pr_transition-delay.asp
$delay-increment: 0.3;
$delay: 0-$delay-increment;
@for $i from 1 through 10 { //adding transition delays to provide sequential icons show on profile load
li:nth-child(#{$i}) {
transition-delay: #{$delay+$delay-increment}s;
&:after{
transition-delay: #{$delay+$delay-increment}s;
}
}
$delay: $delay + $delay-increment;
}
显示<li>
我使用 JS 只是为了设置show
负责不透明度更改的类
请参阅下面的已编译 sass 示例:
$('.show').click(function() {
$('ul').toggleClass('show');
})
li:nth-child(1) {
transition-delay: 0s;
}
li:nth-child(2) {
transition-delay: 0.3s;
}
li:nth-child(3) {
transition-delay: 0.6s;
}
li:nth-child(4) {
transition-delay: 0.9s;
}
li:nth-child(5) {
transition-delay: 1.2s;
}
li:nth-child(6) {
transition-delay: 1.5s;
}
li:nth-child(7) {
transition-delay: 1.8s;
}
li:nth-child(8) {
transition-delay: 2.1s;
}
li:nth-child(9) {
transition-delay: 2.4s;
}
li:nth-child(10) {
transition-delay: 2.7s;
}
ul>li {
opacity: 0;
transition: opacity .4s;
}
ul.show>li {
opacity: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class='show'>Show</button>
<ul>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
</ul>