css3动画次数限制

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<style> 
div
{
    width:100px;
    height:100px;
    background:red;
    position:relative;
    animation:mymove 3s;
    animation-iteration-count:3;

    /* Safari and Chrome */
    -webkit-animation:mymove 3s;
    -webkit-animation-iteration-count:3;
}

@keyframes mymove
{
    from {top:0px;}
    to {top:200px;}
}

@-webkit-keyframes mymove /* Safari and Chrome */
{
    from {top:0px;}
    to {top:200px;}
}
</style>
</head>
<body>

<p><strong>注意:</strong> Internet Explorer 9 及更早 IE 版本浏览器不支持 animation-iteration-count 属性。</p>

<div></div>

</body>
</html>

css3动画不循环可以使用animation-iteration-count属性定义动画的播放次数。

只需要在动画中添加“animation-iteration-count:infinite;”或者不写,即可实现无限次循环。
animation-iteration-count :n;定义动画的播放n次。

.state {
    position: absolute; bottom: 65px; right: 180px; z-index: 100000000;
}

.state p {
    padding: 5px 50px 5px 20px;
    font-size: 13px;
    color: #333;
    font-weight: bold;
    border-radius: 25px;
}

.state.into p {
    background: #999;
}

.state.out p {
    background: #FF5465;
}

.state {
    opacity: 0;
    animation: animate2 2s ease-in-out infinite;
    -webkit-animation: animate2 2s ease-in-out infinite;
    animation-iteration-count:1;
    -webkit-animation-iteration-count:1;
}

@keyframes animate2 {
    0% {
        bottom: 65px;
    }

    30% {
        bottom: 95px;
        opacity: 1;
    }

    70% {
        bottom: 135px;
        opacity: 0.8;
    }

    100% {
        bottom: 170px;
        opacity: 0;
    }
}
<div class="state">
    <p>走你!</p>
</div>

 

posted @ 2022-10-26 16:27  a瑶池  阅读(393)  评论(0编辑  收藏  举报