html5 – 使用CSS3不断向上动画气泡?

前端之家收集整理的这篇文章主要介绍了html5 – 使用CSS3不断向上动画气泡?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
见下图:

http://i.imgur.com/3vTrB.png

后台查看那些透明圆圈?我想要做的是让它们从下往上动画,然后手动跳下(屏幕外)并重新开始动画.圆圈很简单< span>具有border-radius的元素可以产生圆形效果.

这可能与CSS3有关,还是我需要javascript?如果可能的话,我也希望在向上移动的同时在X范围内随机移动圆圈.我会想象随机性需要javascript吗?

如果可能的话,我会很感激有关如何制作它的一些建议/想法.如果不能用CSS,Javascript库也是受欢迎的!

解决方法

这是一个纯粹的CSS demonstration(改编自 tutorial),它依赖于动画属性.更新:感谢TonioElGringo,现在气泡也会向侧面移动,虽然运动是有节奏的,而不是随机的:
html,body,#bubbles { height: 100% }
body { overflow: hidden }
#bubbles { padding: 100px 0 }
.bubble {
    width: 60px;
    height: 60px;
    background: #ffb200;
    border-radius: 200px;
    -moz-border-radius: 200px;
    -webkit-border-radius: 200px;
    position: absolute;
}

.x1 {
    -webkit-transform: scale(0.9);
    -moz-transform: scale(0.9);
    transform: scale(0.9);
    opacity: 0.2;
    -webkit-animation: moveclouds 15s linear infinite,sideWays 4s ease-in-out infinite alternate;
    -moz-animation: moveclouds 15s linear infinite,sideWays 4s ease-in-out infinite alternate;
    -o-animation: moveclouds 15s linear infinite,sideWays 4s ease-in-out infinite alternate;
}

.x2 {
    left: 200px;
    -webkit-transform: scale(0.6);
    -moz-transform: scale(0.6);
    transform: scale(0.6);
    opacity: 0.5;
    -webkit-animation: moveclouds 25s linear infinite,sideWays 5s ease-in-out infinite alternate;
    -moz-animation: moveclouds 25s linear infinite,sideWays 5s ease-in-out infinite alternate;
    -o-animation: moveclouds 25s linear infinite,sideWays 5s ease-in-out infinite alternate;
}
.x3 {
    left: 350px;
    -webkit-transform: scale(0.8);
    -moz-transform: scale(0.8);
    transform: scale(0.8);
    opacity: 0.3;
    -webkit-animation: moveclouds 20s linear infinite,sideWays 4s ease-in-out infinite alternate;
    -moz-animation: moveclouds 20s linear infinite,sideWays 4s ease-in-out infinite alternate;
    -o-animation: moveclouds 20s linear infinite,sideWays 4s ease-in-out infinite alternate;
}
.x4 {
    left: 470px;
    -webkit-transform: scale(0.75);
    -moz-transform: scale(0.75);
    transform: scale(0.75);
    opacity: 0.35;
    -webkit-animation: moveclouds 18s linear infinite,sideWays 2s ease-in-out infinite alternate;
    -moz-animation: moveclouds 18s linear infinite,sideWays 2s ease-in-out infinite alternate;
    -o-animation: moveclouds 18s linear infinite,sideWays 2s ease-in-out infinite alternate;
}
.x5 {
    left: 150px;
    -webkit-transform: scale(0.8);
    -moz-transform: scale(0.8);
    transform: scale(0.8);
    opacity: 0.3;
    -webkit-animation: moveclouds 7s linear infinite,sideWays 1s ease-in-out infinite alternate;
    -moz-animation: moveclouds 7s linear infinite,sideWays 1s ease-in-out infinite alternate;
    -o-animation: moveclouds 7s linear infinite,sideWays 1s ease-in-out infinite alternate;
}
@-webkit-keyframes moveclouds {
    0% {
        top: 500px;
    }
    100% {
        top: -500px;
    }
}

@-webkit-keyframes sideWays {
    0% {
        margin-left:0px;
    }
    100% {
        margin-left:50px;
    }
}

@-moz-keyframes moveclouds {     
    0% {
        top: 500px;
    }

    100% {
        top: -500px;
    }
}

@-moz-keyframes sideWays {
    0% {
        margin-left:0px;
    }
    100% {
        margin-left:50px;
    }
}
@-o-keyframes moveclouds {
    0% {
        top: 500px;
    }
    100% {
        top: -500px;
    }
}

@-o-keyframes sideWays {
    0% {
        margin-left:0px;
    }
    100% {
        margin-left:50px;
    }
}
原文链接:https://www.f2er.com/html5/168558.html

猜你在找的HTML5相关文章