在CSS中的@keyframe动画问题

时间:2015-02-26 05:32:24

标签: html css css3 keyframe

我在CSS中尝试了一个动画,但是遇到了一个无效的问题。 这是我的fiddle

ul {
    display: block;
}
ul>li {
    list-style-type: none;
    transition: all 0.5s ease-out;
}
ul>li:nth-child(1) {
    height:100px;
    width: 100px;
    background: transparent;
    border-radius: 100%;
    border:solid 5px #00f;
    border-right: transparent;
    border-left: transparent;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left:0;
    margin: auto;
    animation: spin 1s infinite ease-out;
}
ul>li:nth-child(2) {
    height:75px;
    width: 75px;
    background: transparent;
    border-radius: 100%;
    border:solid 5px #0f0;
    border-top: transparent;
    border-bottom: transparent;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left:0;
    margin: auto;
    animation: spin2 1s infinite ease-out;
}
ul>li:nth-child(3) {
    height:50px;
    width: 50px;
    background: transparent;
    border-radius: 100%;
    border:solid 5px #f00;
    border-left: transparent;
    border-right: transparent;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left:0;
    margin: auto;
    animation: spin3 1s infinite ease-out;
}
@keyframes spin1 {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}
@keyframes spin2 {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}
@keyframes spin3 {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

1 个答案:

答案 0 :(得分:0)

添加browser prefixes,并且您正在为不存在的第一个li使用动画名称旋转。

    ul {
        display: block;
        width: 200px;
        height: 200px;
        margin: 0 auto;
    }
    ul>li {
        list-style-type: none;
    }
    ul>li:nth-child(1) {
        height:100px;
        width: 100px;
        background: transparent;
        border-radius: 100%;
        border:solid 5px #00f;
        border-right: transparent;
        border-left: transparent;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left:0;
        margin: auto;
        -webkit-animation: spin1 5s infinite ease-out;
        animation: spin1 5s infinite ease-out;
    }
    ul>li:nth-child(2) {
        height:75px;
        width: 75px;
        background: transparent;
        border-radius: 100%;
        border:solid 5px #0f0;
        border-top: transparent;
        border-bottom: transparent;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left:0;
        margin: auto;
        -webkit-animation: spin2 5s infinite ease-out;
        animation: spin2 5s infinite ease-out;
    }
    ul>li:nth-child(3) {
        height:50px;
        width: 50px;
        background: transparent;
        border-radius: 100%;
        border:solid 5px #f00;
        border-left: transparent;
        border-right: transparent;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left:0;
        margin: auto;
        -webkit-animation: spin3 5s infinite ease-out;
        animation: spin3 5s infinite ease-out;
    }
    @-webkit-keyframes spin1 {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    }
    @-webkit-keyframes spin2 {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    }
    @-webkit-keyframes spin3 {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    }
    @keyframes spin1 {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    }
    @keyframes spin2 {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    }
    @keyframes spin3 {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    }
<ul>
    <li></li>
    <li></li>
    <li></li>
</ul>