html - 单个 HTML 元素中的 CSS 动画

标签 html css

我有这个 CSS 加载器:

http://jsfiddle.net/SPFgH/3/

HTML:

<div id="fountainG"> <i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></div>

CSS:

#fountainG {
    position:relative;
    margin-left: calc(50% - 120px);
    width:240px;
    height:29px
}
#fountainG i {
    position:absolute;
    top:0;
    background-color:#A300A3;
    width:29px;
    height:29px;
    animation-name:bounce_fountainG;
    animation-duration:1.3s;
    animation-iteration-count:infinite;
    animation-direction:linear;
    transform:scale(.3);
    border-radius:19px;
}
#fountainG i:nth-child(1) {
    left:0;
    animation-delay:0.52s;
}
#fountainG i:nth-child(2) {
    left:30px;
    animation-delay:0.65s;
}
#fountainG i:nth-child(3) {
    left:60px;
    animation-delay:0.78s;
}
#fountainG i:nth-child(4) {
    left:90px;
    -webkit-animation-delay:0.91s;
    -ms-animation-delay:0.91s;
}
#fountainG i:nth-child(5) {
    left:120px;
    -webkit-animation-delay:1.04s;
    -ms-animation-delay:1.04s;
}
#fountainG i:nth-child(6) {
    left:150px;
    animation-delay:1.17s;
}
#fountainG i:nth-child(7) {
    left:180px;
    animation-delay:1.3s;
}
#fountainG i:nth-child(8) {
    left:210px;
    animation-delay:1.43s;
}
@keyframes bounce_fountainG {
    0% {
        transform:scale(1);
        background-color:#A300A3;
    }
    100% {
        transform:scale(.3);
        background-color:#999999;
    }
}

我需要将其转换为具有单个 HTML 元素的 CSS 动画。 我可以使用 :before:after 伪元素来添加 8 个子元素中的 2 个,但如何添加所有 8 个元素?

最佳答案

如果您只需要一个 I 标签就可以播放动画

#fountainG {
    position:relative;
    margin-left: calc(50% - 120px);
    width:240px;
    height:29px
}
#fountainG i {
    position:absolute;
    top:0;
    background-color:#A300A3;
    width:29px;
    height:29px;
    animation-name:bounce_fountainG;
    animation-duration:1.3s;
    animation-iteration-count:infinite;
    animation-direction:linear;
    transform:scale(.3);
    border-radius:19px;
}
#fountainG i:nth-child(1) {
    left:0;
    animation-delay:0.52s;
}

@keyframes bounce_fountainG {
    0% {
        transform:scale(1);
        background-color:#A300A3;
    }
    100% {
        transform:scale(.3);
        background-color:#999999;
    }
}

试试这个,看看你试过没有

关于html - 单个 HTML 元素中的 CSS 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18673403/

相关文章:

野外的 HTML5 样式示例?

javascript - 数据表上的 Bootstrap 按钮未呈现

javascript - 更改 "AR.JS"中对象(.dae 或 gltf)的颜色

html - 嵌套表格宽度问题

html - 我可以有一个不可点击的链接部分吗?

javascript - 我们可以使用 jquery 更改 html 或 body 高度吗?

html - 如何修复 Chrome 中的 float 页脚?

html - 根据框架集中的第二帧滚动整个窗口

javascript - 如何在 Javascript 中使用表单值推送 2D 数组

php - 邮件中的 html 未显示。内联图像确实