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

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

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

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

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

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

解决方法

这是一个纯粹的CSS demonstration(改编自 tutorial),它依赖于动画属性.更新:感谢TonioElGringo,现在气泡也会向侧面移动,虽然运动是有节奏的,而不是随机的:
  1. html,body,#bubbles { height: 100% }
  2. body { overflow: hidden }
  3. #bubbles { padding: 100px 0 }
  4. .bubble {
  5. width: 60px;
  6. height: 60px;
  7. background: #ffb200;
  8. border-radius: 200px;
  9. -moz-border-radius: 200px;
  10. -webkit-border-radius: 200px;
  11. position: absolute;
  12. }
  13.  
  14. .x1 {
  15. -webkit-transform: scale(0.9);
  16. -moz-transform: scale(0.9);
  17. transform: scale(0.9);
  18. opacity: 0.2;
  19. -webkit-animation: moveclouds 15s linear infinite,sideWays 4s ease-in-out infinite alternate;
  20. -moz-animation: moveclouds 15s linear infinite,sideWays 4s ease-in-out infinite alternate;
  21. -o-animation: moveclouds 15s linear infinite,sideWays 4s ease-in-out infinite alternate;
  22. }
  23.  
  24. .x2 {
  25. left: 200px;
  26. -webkit-transform: scale(0.6);
  27. -moz-transform: scale(0.6);
  28. transform: scale(0.6);
  29. opacity: 0.5;
  30. -webkit-animation: moveclouds 25s linear infinite,sideWays 5s ease-in-out infinite alternate;
  31. -moz-animation: moveclouds 25s linear infinite,sideWays 5s ease-in-out infinite alternate;
  32. -o-animation: moveclouds 25s linear infinite,sideWays 5s ease-in-out infinite alternate;
  33. }
  34. .x3 {
  35. left: 350px;
  36. -webkit-transform: scale(0.8);
  37. -moz-transform: scale(0.8);
  38. transform: scale(0.8);
  39. opacity: 0.3;
  40. -webkit-animation: moveclouds 20s linear infinite,sideWays 4s ease-in-out infinite alternate;
  41. -moz-animation: moveclouds 20s linear infinite,sideWays 4s ease-in-out infinite alternate;
  42. -o-animation: moveclouds 20s linear infinite,sideWays 4s ease-in-out infinite alternate;
  43. }
  44. .x4 {
  45. left: 470px;
  46. -webkit-transform: scale(0.75);
  47. -moz-transform: scale(0.75);
  48. transform: scale(0.75);
  49. opacity: 0.35;
  50. -webkit-animation: moveclouds 18s linear infinite,sideWays 2s ease-in-out infinite alternate;
  51. -moz-animation: moveclouds 18s linear infinite,sideWays 2s ease-in-out infinite alternate;
  52. -o-animation: moveclouds 18s linear infinite,sideWays 2s ease-in-out infinite alternate;
  53. }
  54. .x5 {
  55. left: 150px;
  56. -webkit-transform: scale(0.8);
  57. -moz-transform: scale(0.8);
  58. transform: scale(0.8);
  59. opacity: 0.3;
  60. -webkit-animation: moveclouds 7s linear infinite,sideWays 1s ease-in-out infinite alternate;
  61. -moz-animation: moveclouds 7s linear infinite,sideWays 1s ease-in-out infinite alternate;
  62. -o-animation: moveclouds 7s linear infinite,sideWays 1s ease-in-out infinite alternate;
  63. }
  64. @-webkit-keyframes moveclouds {
  65. 0% {
  66. top: 500px;
  67. }
  68. 100% {
  69. top: -500px;
  70. }
  71. }
  72.  
  73. @-webkit-keyframes sideWays {
  74. 0% {
  75. margin-left:0px;
  76. }
  77. 100% {
  78. margin-left:50px;
  79. }
  80. }
  81.  
  82. @-moz-keyframes moveclouds {
  83. 0% {
  84. top: 500px;
  85. }
  86.  
  87. 100% {
  88. top: -500px;
  89. }
  90. }
  91.  
  92. @-moz-keyframes sideWays {
  93. 0% {
  94. margin-left:0px;
  95. }
  96. 100% {
  97. margin-left:50px;
  98. }
  99. }
  100. @-o-keyframes moveclouds {
  101. 0% {
  102. top: 500px;
  103. }
  104. 100% {
  105. top: -500px;
  106. }
  107. }
  108.  
  109. @-o-keyframes sideWays {
  110. 0% {
  111. margin-left:0px;
  112. }
  113. 100% {
  114. margin-left:50px;
  115. }
  116. }

猜你在找的HTML5相关文章