7-2 星星与水波
本节编程练习不计算学习进度,请电脑登录imooc.com操作

星星与水波

这一节主要涉及2个动画效果,一个是天上的星星闪烁,一个是桥下的水波左右晃动,具体可以观察右边的效果展示区域

星星部分:

布局上来说没什么难点,一共有6个div元素,背景都是同一张图片,通过left与top修改每一个div的坐标点。唯一的动画就是闪烁,实现上有3种手段

水波部分:

布局上4个div元素并且每个元素赋予不同的图片,同样的也是通过absolute定位,top与left赋予坐标。水波的动作也是很简单,就是两边不断的移动,实现上也有很多方式

区别transition与animation的使用

transition与animation用的很多,这里简单的描述下不同点,transition需要事件触发,animation可以直接自动触发,而且功能上更为强大,包括可以设置不同时间段的动画规则,还有状态的控制,事件等等。

星星与水波动画有个共同的特点

所以针对这个相同点,最终采用了最简单的animation处理。 星星来说可以增加一个opacity变化的的关键帧,1到0重复变化就能达到一个闪烁的效果,水波可以设定translateX变化的值,可以实现左右晃动的效果。需要注意的是,每一个元素的动画执行会有个先后循序,所以需给每一个元素分别单独设置animation-delay延时这个属性。

任务

在代码编辑器pageC.css文件中第182、188、194、200、206、212行填写animation动画使星星闪动起来

-webkit-animation-duration: 5s;
-moz-animation-duration: 5s;
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  6. <title>慕课七夕主题</title>
  7. <link rel='stylesheet' href='style.css' />
  8. <link rel='stylesheet' href='pageA.css' />
  9. <link rel='stylesheet' href='pageB.css' />
  10. <link rel='stylesheet' href='pageC.css' />
  11. <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
  12. <script type="text/javascript" src="http://img1.sycdn.imooc.com//down/55ac9ea30001ace700000000.js"></script>
  13. </head>
  14.  
  15. <body>
  16. <div id='content'>
  17. <ul class='content-wrap'>
  18. <!-- 第一副画面 -->
  19. <li>
  20. <!-- 背景 -->
  21. <div class="a_background">
  22. <div class="a_background_top"></div>
  23. <div class="a_background_middle"></div>
  24. <div class="a_background_botton"></div>
  25. </div>
  26. <!-- 云 -->
  27. <div class="cloudArea">
  28. <div class="cloud"></div>
  29. <div class="cloud"></div>
  30. </div>
  31. <!-- 太阳 -->
  32. <div id="sun"></div>
  33. </li>
  34. <!-- 第二副画面 -->
  35. <li>
  36. <!-- 背景图 -->
  37. <div class="b_background"></div>
  38. <div class="b_background_preload"></div>
  39. <!-- 商店 -->
  40. <div class="shop">
  41. <div class="door">
  42. <div class="door-left"></div>
  43. <div class="door-right"></div>
  44. </div>
  45. <!-- 灯 -->
  46. <div class="lamp"></div>
  47. </div>
  48. <!-- 鸟 -->
  49. <div class="bird"></div>
  50. </li>
  51. <!-- 第三副画面 -->
  52. <li>
  53. <!-- 背景图 -->
  54. <div class="c_background">
  55. <div class="c_background_top"></div>
  56. <div class="c_background_middle"></div>
  57. <div class="c_background_botton"></div>
  58. </div>
  59. <!-- 小女孩 -->
  60. <div class="girl"></div>
  61. <!-- 水波 -->
  62. <div class="bridge-bottom">
  63. <div class="water">
  64. <div id="water1" class="water_1"></div>
  65. <div id="water2" class="water_2"></div>
  66. <div id="water3" class="water_3"></div>
  67. <div id="water4" class="water_4"></div>
  68. </div>
  69. </div>
  70. <!-- 星星 -->
  71. <ul class="stars">
  72. <li class="stars1"></li>
  73. <li class="stars2"></li>
  74. <li class="stars3"></li>
  75. <li class="stars4"></li>
  76. <li class="stars5"></li>
  77. <li class="stars6"></li>
  78. </ul>
  79. </li>
  80. </ul>
  81. </div>
  82. </body>
  83. <script type="text/javascript">
  84. $(function() {
  85.  
  86. var container = $("#content");
  87. var swipe = Swipe(container);
  88. var visualWidth = container.width();
  89. // 页面滚动到指定的位置
  90. function scrollTo(time, proportionX) {
  91. var distX = visualWidth * proportionX;
  92. swipe.scrollTo(distX, time);
  93. }
  94.  
  95. // 获取数据
  96. var getValue = function(className) {
  97. var $elem = $('' + className + '');
  98. // 走路的路线坐标
  99. return {
  100. height: $elem.height(),
  101. top: $elem.position().top
  102. };
  103. };
  104.  
  105. // 桥的Y轴
  106. var bridgeY = function() {
  107. var data = getValue('.c_background_middle');
  108. return data.top;
  109. }();
  110.  
  111. ////////////////////////////////////////////////////////
  112. // ================= 动画处理 ======================= //
  113. ////////////////////////////////////////////////////////
  114.  
  115. // 用来临时调整页面
  116. swipe.scrollTo(visualWidth * 2, 0);
  117.  
  118. ////////
  119. //小女孩 //
  120. ////////
  121. var girl = {
  122. elem: $('.girl'),
  123. getHeight: function() {
  124. return this.elem.height()
  125. },
  126. setOffset: function() {
  127. this.elem.css({
  128. left: visualWidth / 2,
  129. top: bridgeY - this.getHeight()
  130. });
  131. }
  132. };
  133.  
  134. //修正小女孩位置
  135. girl.setOffset();
  136.  
  137. })
  138. </script>
  139. <script type="text/javascript" src="Swipe.js"></script>
  140. <script type="text/javascript" src="Qixi.js"></script>
  141.  
  142. </html>
  1. ///////////
  2. //灯动画 //
  3. ///////////
  4. var lamp = {
  5. elem: $('.b_background'),
  6. bright: function() {
  7. this.elem.addClass('lamp-bright');
  8. },
  9. dark: function() {
  10. this.elem.removeClass('lamp-bright');
  11. }
  12. };
  13.  
  14.  
  15. function doorAction(left, right, time) {
  16. var $door = $('.door');
  17. var doorLeft = $('.door-left');
  18. var doorRight = $('.door-right');
  19. var defer = $.Deferred();
  20. var count = 2;
  21. // 等待开门完成
  22. var complete = function() {
  23. if (count == 1) {
  24. defer.resolve();
  25. return;
  26. }
  27. count--;
  28. };
  29. doorLeft.transition({
  30. 'left': left
  31. }, time, complete);
  32. doorRight.transition({
  33. 'left': right
  34. }, time, complete);
  35. return defer;
  36. }
  37.  
  38. // 开门
  39. function openDoor() {
  40. return doorAction('-50%', '100%', 2000);
  41. }
  42.  
  43. // 关门
  44. function shutDoor() {
  45. return doorAction('0%', '50%', 2000);
  46. }
  47.  
  48.  
  49. var instanceX;
  50.  
  51. /**
  52.   * 小孩走路
  53.   * @param {[type]} container [description]
  54.   */
  55. function BoyWalk() {
  56.  
  57. var container = $("#content");
  58. // 页面可视区域
  59. var visualWidth = container.width();
  60. var visualHeight = container.height();
  61.  
  62. // 获取数据
  63. var getValue = function(className) {
  64. var $elem = $('' + className + '');
  65. // 走路的路线坐标
  66. return {
  67. height: $elem.height(),
  68. top: $elem.position().top
  69. };
  70. }
  71. // 路的Y轴
  72. var pathY = function() {
  73. var data = getValue('.a_background_middle');
  74. return data.top + data.height / 2;
  75. }();
  76.  
  77. var $boy = $("#boy");
  78. var boyWidth = $boy.width();
  79. var boyHeight = $boy.height();
  80.  
  81. // 设置下高度
  82. $boy.css({
  83. top: pathY - boyHeight + 25
  84. })
  85.  
  86. // 暂停走路
  87. function pauseWalk() {
  88. $boy.addClass('pauseWalk');
  89. }
  90.  
  91. // 恢复走路
  92. function restoreWalk() {
  93. $boy.removeClass('pauseWalk');
  94. }
  95.  
  96. // css3的动作变化
  97. function slowWalk() {
  98. $boy.addClass('slowWalk');
  99. }
  100.  
  101. // 用transition做运动
  102. function stratRun(options, runTime) {
  103. var dfdPlay = $.Deferred();
  104. // 恢复走路
  105. restoreWalk();
  106. // 运动的属性
  107. $boy.transition(
  108. options,
  109. runTime,
  110. 'linear',
  111. function() {
  112. dfdPlay.resolve(); // 动画完成
  113. });
  114. return dfdPlay;
  115. }
  116.  
  117. // 开始走路
  118. function walkRun(time, dist, disY) {
  119. time = time || 3000;
  120. // 脚动作
  121. slowWalk();
  122. // 开始走路
  123. var d1 = stratRun({
  124. 'left': dist + 'px',
  125. 'top': disY ? disY : undefined
  126. }, time);
  127. return d1;
  128. }
  129.  
  130.  
  131. // 走进商店
  132. function walkToShop(runTime) {
  133. var defer = $.Deferred();
  134. var doorObj = $('.door')
  135. // 门的坐标
  136. var offsetDoor = doorObj.offset();
  137. var doorOffsetLeft = offsetDoor.left;
  138. var doorOffsetTop = offsetDoor.top;
  139. // 小孩当前的坐标
  140. var posBoy = $boy.position();
  141. var boyPoxLeft = posBoy.left;
  142. var boyPoxTop = posBoy.top;
  143.  
  144. // 中间位置
  145. var boyMiddle = $boy.width() / 2;
  146. var doorMiddle = doorObj.width() / 2;
  147. var doorTopMiddle = doorObj.height() / 2;
  148.  
  149.  
  150. // 当前需要移动的坐标
  151. instanceX = (doorOffsetLeft + doorMiddle) - (boyPoxLeft + boyMiddle);
  152.  
  153. //Y的坐标
  154. // top = 人物底部的top - 门中见的top值
  155. instanceY = boyPoxTop + boyHeight - doorOffsetTop + (doorTopMiddle);
  156.  
  157. // 开始走路
  158. var walkPlay = stratRun({
  159. transform: 'translateX(' + instanceX + 'px),translateY(-'+ instanceY +'px),scale(0.5,0.5)',
  160. opacity: 0.1
  161. }, 2000);
  162. // 走路完毕
  163. walkPlay.done(function() {
  164. $boy.css({
  165. opacity: 0
  166. });
  167. defer.resolve();
  168. });
  169. return defer;
  170. }
  171.  
  172. // 走出店
  173. function walkOutShop(runTime) {
  174. var defer = $.Deferred();
  175. restoreWalk();
  176. // 开始走路
  177. var walkPlay = stratRun({
  178. transform: 'translateX(' + instanceX + 'px),translateY(0),scale(1,1)',
  179. opacity: 1
  180. }, runTime);
  181. // 走路完毕
  182. walkPlay.done(function() {
  183. defer.resolve();
  184. })
  185. return defer;
  186. }
  187.  
  188.  
  189. // 计算移动距离
  190. function calculateDist(direction, proportion) {
  191. return (direction == "x" ?
  192. visualWidth : visualHeight) * proportion;
  193. }
  194.  
  195. return {
  196. // 开始走路
  197. walkTo: function(time, proportionX, proportionY) {
  198. var distX = calculateDist('x', proportionX)
  199. var distY = calculateDist('y', proportionY)
  200. return walkRun(time, distX, distY);
  201. },
  202. // 走进商店
  203. toShop: function() {
  204. return walkToShop.apply(null, arguments);
  205. },
  206. // 走出商店
  207. outShop: function() {
  208. return walkOutShop.apply(null, arguments);
  209. },
  210. // 停止走路
  211. stopWalk: function() {
  212. pauseWalk();
  213. },
  214. setColoer: function(value) {
  215. $boy.css('background-color', value);
  216. }
  217. }
  218. }
  1. /////////
  2. //页面滑动 //
  3. /////////
  4.  
  5.  
  6. /**
  7.  * [Swipe description]
  8.  * @param {[type]} container [页面容器节点]
  9.  * @param {[type]} options [参数]
  10.  */
  11. function Swipe(container) {
  12. // 获取第一个子节点
  13. var element = container.find(":first");
  14. var swipe = {};
  15.  
  16. // li页面数量
  17. var slides = element.find(">");
  18.  
  19. // 获取容器尺寸
  20. var width = container.width();
  21. var height = container.height();
  22.  
  23. // 设置li页面总宽度
  24. element.css({
  25. width: (slides.length * width) + 'px',
  26. height: height + 'px'
  27. });
  28.  
  29. // 设置每一个页面li的宽度
  30. $.each(slides, function(index) {
  31. var slide = slides.eq(index); // 获取到每一个li元素
  32. slide.css({
  33. width: width + 'px',
  34. height: height + 'px'
  35. });
  36. });
  37.  
  38. // 监控完成与移动
  39. swipe.scrollTo = function(x, speed) {
  40. // 执行动画移动
  41. element.css({
  42. 'transition-timing-function' : 'linear',
  43. 'transition-duration' : speed + 'ms',
  44. 'transform' : 'translate3d(-' + x + 'px,0px,0px)'
  45. });
  46. return this;
  47. };
  48.  
  49. return swipe;
  50. }
  1. * {
  2. padding: 0;
  3. margin: 0;
  4. }
  5.  
  6. ol,
  7. ul,
  8. li {
  9. list-style-type: none;
  10. }
  11. /*主体部分*/
  12.  
  13. #content {
  14. width: 100%;
  15. height: 100%;
  16. /* top: 20%; */
  17. overflow: hidden;
  18. position: absolute;
  19. }
  20.  
  21. .content-wrap {
  22. position: relative;
  23. }
  24.  
  25. .content-wrap > li {
  26. background: #CAE1FF;
  27. color: red;
  28. float: left;
  29. overflow: hidden;
  30. position: relative;
  31. }
  32.  
  33. a {
  34. position: absolute;
  35. top: 50%;
  36. left: 40%;
  37. }
  38.  
  39. .charector {
  40. position: absolute;
  41. left: 0%;
  42. top: 55%;
  43. position: absolute;
  44. width: 100%;
  45. height: 100%;
  46. width: 151px;
  47. height: 291px;
  48. background: url(http://img.mukewang.com/55ade248000198ae10550582.png) -0px -291px no-repeat;
  49. }
  50. /*人物暂停*/
  51.  
  52. .pauseWalk {
  53. -webkit-animation-play-state: paused;
  54. }
  55.  
  56. .slowWalk {
  57. -webkit-animation-name: person-slow;
  58. -webkit-animation-duration: 950ms;
  59. -webkit-animation-iteration-count: infinite;
  60. -webkit-animation-timing-function: steps(1, start);
  61. -moz-animation-name: person-slow;
  62. -moz-animation-duration: 950ms;
  63. -moz-animation-iteration-count: infinite;
  64. -moz-animation-timing-function: steps(1, start)
  65. }
  66. /*普通慢走*/
  67.  
  68. @-webkit-keyframes person-slow {
  69. 0% {
  70. background-position: -0px -291px;
  71. }
  72. 25% {
  73. background-position: -602px -0px;
  74. }
  75. 50% {
  76. background-position: -302px -291px;
  77. }
  78. 75% {
  79. background-position: -151px -291px;
  80. }
  81. 100% {
  82. background-position: -0px -291px;
  83. }
  84. }
  85.  
  86. @-moz-keyframes person-slow {
  87. 0% {
  88. background-position: -0px -291px;
  89. }
  90. 25% {
  91. background-position: -602px -0px;
  92. }
  93. 50% {
  94. background-position: -302px -291px;
  95. }
  96. 75% {
  97. background-position: -151px -291px;
  98. }
  99. 100% {
  100. background-position: -0px -291px;
  101. }
  102. }
  1. /*背景图*/
  2.  
  3. .a_background {
  4. width: 100%;
  5. height: 100%;
  6. /* background-image: url("../images/QixiA.png");
  7.   background-size: 100% 100%;*/
  8.  
  9. position: absolute;
  10. }
  11.  
  12. .a_background_top {
  13. width: 100%;
  14. height: 71.6%;
  15. background-image: url("http://img1.sycdn.imooc.com//55addf6900019d8f14410645.png");
  16. background-size: 100% 100%;
  17. }
  18.  
  19. .a_background_middle {
  20. width: 100%;
  21. height: 13.1%;
  22. background-image: url("http://img1.sycdn.imooc.com//55addf800001ff2e14410118.png");
  23. background-size: 100% 100%;
  24. }
  25.  
  26. .a_background_botton {
  27. width: 100%;
  28. height: 15.3%;
  29. background-image: url("http://img1.sycdn.imooc.com//55addfcb000189b314410138.png");
  30. background-size: 100% 100%;
  31. }
  32.  
  33. button {
  34. width: 80px;
  35. height: 50px;
  36. }
  37.  
  38. .button {
  39. position: absolute;
  40. top: 80%;
  41. }
  42. /*人物暂停*/
  43.  
  44. .pauseWalk {
  45. animation-play-state: paused;
  46. }
  47. /*-------- 太阳自转以及动画 --------*/
  48.  
  49. #sun {
  50. background: url("http://img1.sycdn.imooc.com//55ade004000106c202010201.png") no-repeat;
  51. position: absolute;
  52. z-index: 1;
  53. top: -30px;
  54. height: 201px;
  55. width: 201px;
  56. right: 40%;
  57. }
  58.  
  59. .rotation {
  60. -webkit-animation-name: rotation;
  61. -webkit-animation-duration: 30s;
  62. -webkit-animation-iteration: 1;
  63. -moz-animation-name: rotation;
  64. -moz-animation-duration: 30s;
  65. -moz-animation-iteration: 1;
  66. }
  67.  
  68. @-webkit-keyframes rotation {
  69. 0% {
  70. transform: translateX(0) translateY(0);
  71. }
  72. 100% {
  73. transform: translateX(-2000px) translateY(400px);
  74. }
  75. }
  76.  
  77. @-moz-keyframes rotation {
  78. 0% {
  79. transform: translateX(0) translateY(0);
  80. }
  81. 100% {
  82. transform: translateX(-2000px) translateY(400px);
  83. }
  84. }
  85. /*天空云*/
  86.  
  87. .cloud {
  88. z-index: 2;
  89. position: absolute;
  90. }
  91.  
  92. .cloud1 {
  93. width: 20%;
  94. height: 30%;
  95. left: -5%;
  96. top: 15%;
  97. background: url("http://img1.sycdn.imooc.com//55addfde0001aec501810101.png") no-repeat;
  98. -webkit-animation-name: smallCloud;
  99. -webkit-animation-duration: 30s;
  100. -webkit-animation-iteration: infinite;
  101. -moz-animation-name: smallCloud;
  102. -moz-animation-duration: 30s;
  103. -moz-animation-iteration: infinite
  104. }
  105.  
  106. .cloud2 {
  107. width: 20%;
  108. height: 30%;
  109. right: -5%;
  110. background: url("http://img1.sycdn.imooc.com//55addff500016df503010140.png") no-repeat;
  111. -webkit-animation-name: largeCloud;
  112. -webkit-animation-duration: 60s;
  113. -webkit-animation-iteration: infinite;
  114. -moz-animation-name: largeCloud;
  115. -moz-animation-duration: 60s;
  116. -moz-animation-iteration: infinite;
  117. }
  118.  
  119. @-webkit-keyframes smallCloud {
  120. 0% {
  121. left: -5%;
  122. }
  123. 100% {
  124. left: 100%;
  125. }
  126. }
  127.  
  128. @-moz-keyframes smallCloud {
  129. 0% {
  130. left: -5%;
  131. }
  132. 100% {
  133. left: 100%;
  134. }
  135. }
  136.  
  137. @-webkit-keyframes largeCloud {
  138. 0% {
  139. right: -5%;
  140. }
  141. 100% {
  142. right: 100%;
  143. }
  144. }
  145.  
  146. @-moz-keyframes largeCloud {
  147. 0% {
  148. right: -5%;
  149. }
  150. 100% {
  151. right: 100%;
  152. }
  153. }
  1. /*背景图*/
  2.  
  3. .b_background {
  4. width: 100%;
  5. height: 100%;
  6. background-image: url("http://img1.sycdn.imooc.com//55ade06f00015a0d14410901.png");
  7. background-size: 100% 100%;
  8. position: absolute;
  9. }
  10.  
  11. .b_background_preload {
  12. background: url("http://img1.sycdn.imooc.com//55ade0be0001a37914410901.png") no-repeat -9999px -9999px;
  13. }
  14.  
  15. .lamp-bright {
  16. background-image: url("http://img1.sycdn.imooc.com//55ade0be0001a37914410901.png");
  17. }
  18.  
  19.  
  20. /*商店*/
  21.  
  22. .shop {
  23. width: 39.5%;
  24. height: 35.5%;
  25. position: absolute;
  26. left: 29%;
  27. top: 36.5%;
  28. }
  29.  
  30. .door {
  31. position: absolute;
  32. width: 32%;
  33. height: 100%;
  34. top: 32%;
  35. height: 68%;
  36. overflow: hidden;
  37. left: 58.5%;
  38. }
  39.  
  40. .door-left,
  41. .door-right {
  42. width: 50%;
  43. height: 100%;
  44. position: absolute;
  45. }
  46.  
  47. .door-left {
  48. left: 0%;
  49. background: url(http://img.mukewang.com/55ade1140001050d00910231.png);
  50. background-size: 100% 100%;
  51. }
  52.  
  53. .door-right {
  54. left: 50%;
  55. background: url(http://img.mukewang.com/55ade12100019f5b00910231.png);
  56. background-size: 100% 100%;
  57. }
  58.  
  59.  
  60. /*鸟*/
  61.  
  62. .bird {
  63. min-width: 91px;
  64. min-height: 71px;
  65. top: 10%;
  66. position: absolute;
  67. z-index: 10;
  68. right: -91px;
  69. background: url(http://img.mukewang.com/55ade1700001b38302730071.png) -182px 0px no-repeat;
  70. }
  71. .birdFly {
  72. -webkit-animation-name: bird-slow;
  73. -webkit-animation-duration: 400ms;
  74. -webkit-animation-timing-function: step-start;
  75. -webkit-animation-iteration-count: infinite;
  76. -moz-animation-name: bird-slow;
  77. -moz-animation-duration: 400ms;
  78. -moz-animation-timing-function: step-start;
  79. -moz-animation-iteration-count: infinite;
  80. }
  81.  
  82.  
  83. /*鸟慢飞*/
  84. @-webkit-keyframes bird-slow {
  85. 0% {
  86. background-position: -182px 0px;
  87. }
  88. 50% {
  89. background-position: 0px 0px;
  90. }
  91. 75% {
  92. background-position: -91px 0px;
  93. }
  94. 100% {
  95. background-position: -182px 0px;
  96. }
  97. }
  98.  
  99. @-moz-keyframes bird-slow {
  100. 0% {
  101. background-position: -182px 0px;
  102. }
  103. 50% {
  104. background-position: 0px 0px;
  105. }
  106. 75% {
  107. background-position: -91px 0px;
  108. }
  109. 100% {
  110. background-position: -182px 0px;
  111. }
  112. }
  1. /*背景图*/
  2.  
  3. .c_background {
  4. width: 100%;
  5. height: 100%;
  6. background-size: 100% 100%;
  7. position: absolute;
  8. }
  9.  
  10. .c_background_top{
  11. width: 100%;
  12. height: 71.6%;
  13. background-image: url("http://img1.sycdn.imooc.com//55ade19b0001d92c14410645.png");
  14. background-size: 100% 100%;
  15. }
  16.  
  17.  
  18. .c_background_middle{
  19. width: 100%;
  20. height: 13.1%;
  21. background-image: url("http://img1.sycdn.imooc.com//55ade1b3000135c114410118.png");
  22. background-size: 100% 100%;
  23. }
  24.  
  25. .c_background_botton{
  26. width: 100%;
  27. height: 15.3%;
  28. background-image: url("http://img1.sycdn.imooc.com//55ade1c30001db5d14410138.png");
  29. background-size: 100% 100%;
  30. }
  31.  
  32. /*小女孩*/
  33.  
  34. .girl {
  35. background: url(http://img.mukewang.com/55ade30d000100dc10570291.png) -755px -0px no-repeat;
  36. position: absolute;
  37. right: 40%;
  38. top: 37%;
  39. width: 151px;
  40. height: 291px;
  41. }
  42.  
  43. /*桥*/
  44.  
  45. .bridge-bottom {
  46. position: absolute;
  47. width: 41%;
  48. height: 24%;
  49. left: 29.5%;
  50. top: 76%;
  51. overflow: hidden;
  52. /* -webkit-transform:perspective(8px) rotateX(.8deg); */
  53. }
  54. /*波浪水布局*/
  55.  
  56. .water {
  57. width: 100%;
  58. height: 100%;
  59. }
  60.  
  61. .water_1,
  62. .water_2,
  63. .water_3,
  64. .water_4 {
  65. width: 100%;
  66. position: absolute;
  67. height: 50%;
  68. -webkit-animation-name: shake;
  69. -webkit-animation-duration: 40s;
  70. -webkit-animation-direction: alternate;
  71. -webkit-anination-timing-function: linear;
  72. -webkit-animation-iteration-count: infinite;
  73.  
  74. -moz-animation-name: shake;
  75. -moz-animation-duration: 40s;
  76. -moz-animation-direction: alternate;
  77. -moz-anination-timing-function: linear;
  78. -moz-animation-iteration-count: infinite;
  79. }
  80.  
  81. .water_1 {
  82. width: 131px;
  83. height: 15px;
  84. top: 13%;
  85. left: 35%;
  86. background: url(http://img.mukewang.com/55ade1e000010f2908540027.png) -261px -0px no-repeat;
  87. }
  88.  
  89. .water_2 {
  90. width: 161px;
  91. height: 9px;
  92. top: 28%;
  93. left: 45%;
  94. background: url(http://img.mukewang.com/55ade1e000010f2908540027.png) -693px -0px no-repeat;
  95. -webkit-animation-delay: 2s;
  96. -moz-animation-delay: 2s;
  97. }
  98.  
  99. .water_3 {
  100. width: 261px;
  101. height: 29px;
  102. top: 50%;
  103. left: 15%;
  104. background: url(http://img.mukewang.com/55ade1e000010f2908540027.png) -0px -0px no-repeat;
  105. -webkit-animation-delay: 1s;
  106. -moz-animation-delay: 1s;
  107. }
  108.  
  109. .water_4 {
  110. width: 301px;
  111. height: 12px;
  112. top: 75%;
  113. left: 30%;
  114. background: url(http://img.mukewang.com/55ade1e000010f2908540027.png) -392px -0px no-repeat;
  115. -webkit-animation-delay: 3s;
  116. -moz-animation-delay: 3s;
  117. }
  118.  
  119. @-webkit-keyframes shake {
  120. 0%, 100% {
  121. -webkit-transform: translate3d(0, 0, 0);
  122. }
  123. 10%,
  124. 30%,
  125. 50%,
  126. 70%,
  127. 90% {
  128. -webkit-transform: translate3d(-30px, 0px, 0);
  129. }
  130. 20%,
  131. 40%,
  132. 60%,
  133. 80% {
  134. -webkit-transform: translate3d(30px, 0px, 0);
  135. }
  136. }
  137.  
  138. @-moz-keyframes shake {
  139. 0%, 100% {
  140. -moz-transform: translate3d(0, 0, 0);
  141. }
  142. 10%,
  143. 30%,
  144. 50%,
  145. 70%,
  146. 90% {
  147. -moz-transform: translate3d(-30px, 0px, 0);
  148. }
  149. 20%,
  150. 40%,
  151. 60%,
  152. 80% {
  153. -moz-transform: translate3d(30px, 0px, 0);
  154. }
  155. }
  156. /*星星*/
  157.  
  158. .stars {
  159. width: 100%;
  160. height: 100%;
  161. position: absolute;
  162. }
  163.  
  164. .stars > li {
  165. position: absolute;
  166. width: 30px;
  167. height: 31px;
  168. background-image: url("http://img1.sycdn.imooc.com//55ade1fe00016b8900300031.png");
  169. -webkit-animation-name: flash;
  170. -webkit-animation-timing-function: ease-in-out;
  171. -webkit-animation-iteration-count: infinite;
  172. -webkit-animation-direction: alternate;
  173. -moz-animation-name: flash;
  174. -moz-animation-timing-function: ease-in-out;
  175. -moz-animation-iteration-count: infinite;
  176. -moz-animation-direction: alternate;
  177. }
  178.  
  179. .stars1 {
  180. top: 20%;
  181. left: 30%;
  182. /* ? */
  183. }
  184.  
  185. .stars2 {
  186. top: 15%;
  187. left: 20%;
  188. /* ? */
  189. }
  190.  
  191. .stars3 {
  192. top: 25%;
  193. left: 85%;
  194. /* ? */
  195. }
  196.  
  197. .stars4 {
  198. top: 30%;
  199. left: 70%;
  200. /* ? */
  201. }
  202.  
  203. .stars5 {
  204. top: 25%;
  205. left: 20%;
  206. /* ? */
  207. }
  208.  
  209. .stars6 {
  210. top: 10%;
  211. left: 65%;
  212. /* ? */
  213. }
  214.  
  215. @-webkit-keyframes flash {
  216. 0%, 50%, 100% {
  217. opacity: 1;
  218. }
  219. 25%,
  220. 75% {
  221. opacity: 0;
  222. }
  223. }
  224.  
  225. @-moz-keyframes flash {
  226. 0%, 50%, 100% {
  227. opacity: 1;
  228. }
  229. 25%,
  230. 75% {
  231. opacity: 0;
  232. }
  233. }
下一节