Skip to content

Instantly share code, notes, and snippets.

@xyeig
Last active April 21, 2019 03:50
Show Gist options
  • Save xyeig/0f07e3adc8fb614c93818ab1e884563c to your computer and use it in GitHub Desktop.
Save xyeig/0f07e3adc8fb614c93818ab1e884563c to your computer and use it in GitHub Desktop.
css 元素出现动画
<button onclick="add()">添加</button>
<ul class="list" id="list">
<li>box</li>
</ul>
function add(){
var child = document.createElement('li');
child.innerText = 'box';
document.getElementById('list').appendChild(child);
}
.list{
list-style: none;
width: 200px;
color: #fff;
counter-reset: num;
}
.list li{
padding: 10px;
margin: 10px;
background:slateblue;
animation:show .5s;
}
.list li:after{
counter-increment: num;
content: counter(num)
}
.list li:nth-child(2n + 1) {
background: tomato
}
.list li:nth-child(3n + 2) {
background:royalblue
}
.list li:nth-child(5n + 3) {
background:violet
}
.list li:nth-child(7n + 4) {
background:tan;
color: #000;
}
.list li:nth-child(11n + 5) {
background:yellowgreen
}
@keyframes show{
from {
opacity: 0;
transform: translateX(100px)
}
to {
opacity: 1;
transform: translateX(0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment