7-4 转身与logo效果
本节编程练习不计算学习进度,请电脑登录imooc.com操作

转身与logo效果

转身效果与慕课logo的效果都是通过css3的animation动画实现的

人物转身

具体代码调用部分:通过定时器模拟一个暂停的时间,这样感觉人物会有一个等待转身的效果

setTimeout(function() {
    girl.rotate();
    boy.rotate(function() {
        //开始logo动画
        logo.run()
    });
}, 1000)

girl与boy都增加一个rotate的方法。这是通过增加一个rotate的样式调用CSS3动画,我们在pageC文件中找到对应的rotate样式

-webkit-animation-name: girl-rotate;
-webkit-animation-duration: 850ms;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: step-start;
-webkit-animation-fill-mode: forwards;

定义了一个keyframes的规则,原理同样也是通过position不断更换帧图的坐标,这里会有一个animation-fill-mode的属性,forwards的意思就是保留在最终的状态,也就是我们转身后的最终状态

在转身以后还会继续执行其他的动画,那么转身动作到底多久可以完成?虽然这个动画是850ms的运行时间,但是为了保证精确,一般采用事件监听的方法处理

boy.rotate方法传递一个回调,内部通过jQuery.on方法监听一个动画结束的事件,转身动画结束后会调用这个回调函数

$boy.on(animationEnd, function() {
   callback()
   $(this).off();
})

慕课网Logo

loge动画处理的原理与rotate是一样的,区别就是logo是2组CSS3的animation动画组成。这里需要注意的,不能同时给一个元素增加2个CSS3的关键帧动画,所以需要一个结束后,在增加下一个,这里需要通过事件监听的方式处理

代码调用部分:

this.elem.addClass('logolightSpeedIn')
    .on(animationEnd, function() {
        $(this).addClass('logoshake').off();
    })

增加一个logolightSpeedIn的类执行一个动画,等待这个动画结束后,在增加一个logoshake的动画,具体的关键帧的写法,可以参考下源码部分

任务

在代码编辑器pageC.css样式文件中第370、374行补充代码,使慕课网logo出现左右晃动的效果。

0%, 100% {
    -moz-transform: translate3d(0, 0, 0);
}
10%,
30%,
50%,
70%,
90% {
    -moz-transform: translate3d(-5px, 0, 0);
}
20%,
40%,
60%,
80% {
    -moz-transform: translate3d(10px, 0, 0);
}
  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. <div class="bridge-bottom">
  62. <div class="water">
  63. <div id="water1" class="water_1"></div>
  64. <div id="water2" class="water_2"></div>
  65. <div id="water3" class="water_3"></div>
  66. <div id="water4" class="water_4"></div>
  67. </div>
  68. </div>
  69. <!-- 星星 -->
  70. <ul class="stars">
  71. <li class="stars1"></li>
  72. <li class="stars2"></li>
  73. <li class="stars3"></li>
  74. <li class="stars4"></li>
  75. <li class="stars5"></li>
  76. <li class="stars6"></li>
  77. </ul>
  78. <!-- 慕课网logo图 -->
  79. <div class="logo"></div>
  80. </li>
  81. </ul>
  82. <div id="boy" class="charector"></div>
  83. </div>
  84. <div class="button">
  85. <button>开始</button>
  86. </div>
  87. </body>
  88. <script type="text/javascript">
  89. $(function() {
  90. ////////
  91. //小女孩 //
  92. ////////
  93. var girl = {
  94. elem: $('.girl'),
  95. getHeight: function() {
  96. return this.elem.height();
  97. },
  98. // 转身动作
  99. rotate: function() {
  100. this.elem.addClass('girl-rotate');
  101. },
  102. setPosition: function() {
  103. this.elem.css({
  104. left: visualWidth / 2,
  105. top: bridgeY - this.getHeight()
  106. });
  107. },
  108. getPosition: function() {
  109. return this.elem.position();
  110. },
  111. getWidth: function() {
  112. return this.elem.width()
  113. }
  114. };
  115. // 修正小女孩位置
  116. girl.setPosition();
  117.  
  118.  
  119. ///////////
  120. //loge动画 //
  121. ///////////
  122. var logo = {
  123. elem: $('.logo'),
  124. run: function() {
  125. this.elem.addClass('logolightSpeedIn')
  126. .on(animationEnd, function() {
  127. $(this).addClass('logoshake').off();
  128. });
  129. }
  130. };
  131.  
  132.  
  133. //////////
  134. // 小孩走路 //
  135. //////////
  136. var boy = BoyWalk();
  137.  
  138. boy.talkFlower();
  139.  
  140. // 开始
  141. $("button:first").click(function() {
  142.  
  143. // 第一次走路到桥底边left,top
  144. boy.walkTo(2000, 0.15)
  145. .then(function() {
  146. // 第二次走路到桥上left,top
  147. return boy.walkTo(1500, 0.25, girl.getPosition().top / visualHeight);
  148. })
  149. .then(function() {
  150. // 实际走路的比例
  151. var proportionX = (girl.getPosition().left - boy.getWidth() + girl.getWidth() / 5) / visualWidth;
  152. // 第三次桥上直走到小女孩面前
  153. return boy.walkTo(1500, proportionX);
  154. }).then(function() {
  155. // 图片还原原地停止状态
  156. boy.resetOriginal();
  157. }).then(function() {
  158. // 增加转身动作
  159. setTimeout(function() {
  160. girl.rotate();
  161. boy.rotate(function() {
  162. // 开始logo动画
  163. logo.run();
  164. });
  165. }, 1000);
  166. });
  167. })
  168.  
  169.  
  170. })
  171. </script>
  172. <script type="text/javascript" src="Swipe.js"></script>
  173. <script type="text/javascript" src="Qixi.js"></script>
  174.  
  175. </html>
  1. // 动画结束事件
  2. var animationEnd = (function() {
  3. var explorer = navigator.userAgent;
  4. if (~explorer.indexOf('WebKit')) {
  5. return 'webkitAnimationEnd';
  6. }
  7. return 'animationend';
  8. })();
  9.  
  10.  
  11. ///////////
  12. //灯动画 //
  13. ///////////
  14. var lamp = {
  15. elem: $('.b_background'),
  16. bright: function() {
  17. this.elem.addClass('lamp-bright');
  18. },
  19. dark: function() {
  20. this.elem.removeClass('lamp-bright');
  21. }
  22. };
  23.  
  24. var container = $("#content");
  25. var swipe = Swipe(container);
  26. visualWidth = container.width();
  27. visualHeight = container.height();
  28.  
  29. // 页面滚动到指定的位置
  30. function scrollTo(time, proportionX) {
  31. var distX = visualWidth * proportionX;
  32. swipe.scrollTo(distX, time);
  33. }
  34.  
  35. // 获取数据
  36. var getValue = function(className) {
  37. var $elem = $('' + className + '');
  38. // 走路的路线坐标
  39. return {
  40. height: $elem.height(),
  41. top: $elem.position().top
  42. };
  43. };
  44.  
  45. // 桥的Y轴
  46. var bridgeY = function() {
  47. var data = getValue('.c_background_middle');
  48. return data.top;
  49. }();
  50.  
  51. ////////
  52. //小女孩 //
  53. ////////
  54. var girl = {
  55. elem: $('.girl'),
  56. getHeight: function() {
  57. return this.elem.height();
  58. },
  59. setOffset: function() {
  60. this.elem.css({
  61. left: visualWidth / 2,
  62. top: bridgeY - this.getHeight()
  63. });
  64. }
  65. };
  66.  
  67. // 修正小女孩位置
  68. girl.setOffset();
  69.  
  70.  
  71. // 用来临时调整页面
  72. swipe.scrollTo(visualWidth * 2, 0);
  73.  
  74.  
  75. function doorAction(left, right, time) {
  76. var $door = $('.door');
  77. var doorLeft = $('.door-left');
  78. var doorRight = $('.door-right');
  79. var defer = $.Deferred();
  80. var count = 2;
  81. // 等待开门完成
  82. var complete = function() {
  83. if (count == 1) {
  84. defer.resolve();
  85. return;
  86. }
  87. count--;
  88. };
  89. doorLeft.transition({
  90. 'left': left
  91. }, time, complete);
  92. doorRight.transition({
  93. 'left': right
  94. }, time, complete);
  95. return defer;
  96. }
  97.  
  98. // 开门
  99. function openDoor() {
  100. return doorAction('-50%', '100%', 2000);
  101. }
  102.  
  103. // 关门
  104. function shutDoor() {
  105. return doorAction('0%', '50%', 2000);
  106. }
  107.  
  108. /**
  109.   * 小孩走路
  110.   * @param {[type]} container [description]
  111.   */
  112. function BoyWalk() {
  113.  
  114. var container = $("#content");
  115. // 页面可视区域
  116. var visualWidth = container.width();
  117. var visualHeight = container.height();
  118.  
  119. // 获取数据
  120. var getValue = function(className) {
  121. var $elem = $('' + className + '');
  122. //走路的路线坐标
  123. return {
  124. height: $elem.height(),
  125. top: $elem.position().top
  126. };
  127. };
  128. // 路的Y轴
  129. var pathY = function() {
  130. var data = getValue('.a_background_middle');
  131. return data.top + data.height / 2;
  132. }();
  133.  
  134. var $boy = $("#boy");
  135. var boyHeight = $boy.height();
  136.  
  137. // 设置下高度
  138. $boy.css({
  139. top: pathY - boyHeight + 25
  140. });
  141.  
  142. // 暂停走路
  143. function pauseWalk() {
  144. $boy.addClass('pauseWalk');
  145. }
  146.  
  147. // 恢复走路
  148. function restoreWalk() {
  149. $boy.removeClass('pauseWalk');
  150. }
  151.  
  152. // css3的动作变化
  153. function slowWalk() {
  154. $boy.addClass('slowWalk');
  155. }
  156.  
  157. // 用transition做运动
  158. function stratRun(options, runTime) {
  159. var dfdPlay = $.Deferred();
  160. // 恢复走路
  161. restoreWalk();
  162. // 运动的属性
  163. $boy.transition(
  164. options,
  165. runTime,
  166. 'linear',
  167. function() {
  168. dfdPlay.resolve(); // 动画完成
  169. });
  170. return dfdPlay;
  171. }
  172.  
  173. // 开始走路
  174. function walkRun(time, dist, disY) {
  175. time = time || 3000;
  176. // 脚动作
  177. slowWalk();
  178. // 开始走路
  179. var d1 = stratRun({
  180. 'left': dist + 'px',
  181. 'top': disY ? disY : undefined
  182. }, time);
  183. return d1;
  184. }
  185.  
  186.  
  187. // 走进商店
  188. function walkToShop(runTime) {
  189. var defer = $.Deferred();
  190. var doorObj = $('.door')
  191. // 门的坐标
  192. var offsetDoor = doorObj.offset();
  193. var doorOffsetLeft = offsetDoor.left;
  194. var doorOffsetTop = offsetDoor.top;
  195. // 小孩当前的坐标
  196. var posBoy = $boy.position();
  197. var boyPoxLeft = posBoy.left;
  198. var boyPoxTop = posBoy.top;
  199.  
  200. // 中间位置
  201. var boyMiddle = $boy.width() / 2;
  202. var doorMiddle = doorObj.width() / 2;
  203. var doorTopMiddle = doorObj.height() / 2;
  204.  
  205.  
  206. // 当前需要移动的坐标
  207. instanceX = (doorOffsetLeft + doorMiddle) - (boyPoxLeft + boyMiddle);
  208.  
  209. // Y的坐标
  210. //top = 人物底部的top - 门中见的top值
  211. instanceY = boyPoxTop + boyHeight - doorOffsetTop + (doorTopMiddle);
  212.  
  213. // 开始走路
  214. var walkPlay = stratRun({
  215. transform: 'translateX(' + instanceX + 'px),translateY(-' + instanceY + 'px),scale(0.5,0.5)',
  216. opacity: 0.1
  217. }, 2000);
  218. // 走路完毕
  219. walkPlay.done(function() {
  220. $boy.css({
  221. opacity: 0
  222. })
  223. defer.resolve();
  224. });
  225. return defer;
  226. }
  227.  
  228. // 走出店
  229. function walkOutShop(runTime) {
  230. var defer = $.Deferred();
  231. restoreWalk();
  232. // 开始走路
  233. var walkPlay = stratRun({
  234. transform: 'translateX(' + instanceX + 'px),translateY(0),scale(1,1)',
  235. opacity: 1
  236. }, runTime);
  237. // 走路完毕
  238. walkPlay.done(function() {
  239. defer.resolve();
  240. });
  241. return defer;
  242. }
  243.  
  244.  
  245. // 计算移动距离
  246. function calculateDist(direction, proportion) {
  247. return (direction == "x" ?
  248. visualWidth : visualHeight) * proportion;
  249. }
  250.  
  251. return {
  252. // 开始走路
  253. walkTo: function(time, proportionX, proportionY) {
  254. var distX = calculateDist('x', proportionX)
  255. var distY = calculateDist('y', proportionY)
  256. return walkRun(time, distX, distY);
  257. },
  258. // 走进商店
  259. toShop: function() {
  260. return walkToShop.apply(null, arguments);
  261. },
  262. // 走出商店
  263. outShop: function() {
  264. return walkOutShop.apply(null, arguments);
  265. },
  266. // 停止走路
  267. stopWalk: function() {
  268. pauseWalk();
  269. },
  270. setColoer: function(value) {
  271. $boy.css('background-color', value)
  272. },
  273. // 获取男孩的宽度
  274. getWidth: function() {
  275. return $boy.width();
  276. },
  277. // 复位初始状态
  278. resetOriginal: function() {
  279. this.stopWalk();
  280. // 恢复图片
  281. $boy.removeClass('slowWalk slowFlolerWalk').addClass('boyOriginal');
  282. },
  283. // 转身动作
  284. rotate: function(callback) {
  285. restoreWalk();
  286. $boy.addClass('boy-rotate');
  287. // 监听转身完毕
  288. if (callback) {
  289. $boy.on(animationEnd, function() {
  290. callback();
  291. $(this).off();
  292. })
  293. }
  294. },
  295. // 取花
  296. talkFlower: function() {
  297. $boy.addClass('slowFlolerWalk');
  298. }
  299. }
  300. }
  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. float: left;
  27. overflow: hidden;
  28. position: relative;
  29. }
  30.  
  31. a {
  32. position: absolute;
  33. top: 50%;
  34. left: 40%;
  35. }
  36.  
  37. .charector {
  38. position: absolute;
  39. left: 0%;
  40. top: 55%;
  41. position: absolute;
  42. width: 100%;
  43. height: 100%;
  44. width: 151px;
  45. height: 291px;
  46. background: url(http://img.mukewang.com/55ade248000198ae10550582.png) -0px -291px no-repeat;
  47. }
  48. /*人物暂停*/
  49.  
  50. .pauseWalk {
  51. -webkit-animation-play-state: paused;
  52. }
  53.  
  54. .slowWalk {
  55. -webkit-animation-name: person-slow;
  56. -webkit-animation-duration: 950ms;
  57. -webkit-animation-iteration-count: infinite;
  58. -webkit-animation-timing-function: steps(1, start);
  59. -moz-animation-name: person-slow;
  60. -moz-animation-duration: 950ms;
  61. -moz-animation-iteration-count: infinite;
  62. -moz-animation-timing-function: steps(1, start)
  63. }
  64.  
  65. .slowFlolerWalk {
  66. -webkit-animation-name: person-floler-slow;
  67. -webkit-animation-duration: 950ms;
  68. -webkit-animation-iteration-count: infinite;
  69. -webkit-animation-timing-function: step-start;
  70. -moz-animation-name: person-floler-slow;
  71. -moz-animation-duration: 950ms;
  72. -moz-animation-iteration-count: infinite;
  73. -moz-animation-timing-function: step-start;
  74. }
  75. /*人物暂停*/
  76.  
  77. .boyOriginal {
  78. background-position: -150px -0px;
  79. }
  80. /*带花*/
  81.  
  82. @-webkit-keyframes person-floler-slow {
  83. 0% {
  84. background-position: -453px -0px;
  85. }
  86. 25% {
  87. background-position: -904px -0px;
  88. }
  89. 50% {
  90. background-position: -451px -0px;
  91. }
  92. 75% {
  93. background-position: -753px -0px;
  94. }
  95. 100% {
  96. background-position: -300px -0px;
  97. }
  98. }
  99.  
  100. @-moz-keyframes person-floler-slow {
  101. 0% {
  102. background-position: -453px -0px;
  103. }
  104. 25% {
  105. background-position: -904px -0px;
  106. }
  107. 50% {
  108. background-position: -451px -0px;
  109. }
  110. 75% {
  111. background-position: -753px -0px;
  112. }
  113. 100% {
  114. background-position: -300px -0px;
  115. }
  116. }
  117. /*普通慢走*/
  118.  
  119. @-webkit-keyframes person-slow {
  120. 0% {
  121. background-position: -0px -291px;
  122. }
  123. 25% {
  124. background-position: -602px -0px;
  125. }
  126. 50% {
  127. background-position: -302px -291px;
  128. }
  129. 75% {
  130. background-position: -151px -291px;
  131. }
  132. 100% {
  133. background-position: -0px -291px;
  134. }
  135. }
  136.  
  137. @-moz-keyframes person-slow {
  138. 0% {
  139. background-position: -0px -291px;
  140. }
  141. 25% {
  142. background-position: -602px -0px;
  143. }
  144. 50% {
  145. background-position: -302px -291px;
  146. }
  147. 75% {
  148. background-position: -151px -291px;
  149. }
  150. 100% {
  151. background-position: -0px -291px;
  152. }
  153. }
  154. /*男孩转身*/
  155.  
  156. .boy-rotate {
  157. -webkit-animation-name: boy-rotate;
  158. -webkit-animation-duration: 850ms;
  159. -webkit-animation-iteration-count: 1;
  160. -webkit-animation-timing-function: step-start;
  161. -webkit-animation-fill-mode: forwards;
  162. -moz-animation-name: boy-rotate;
  163. -moz-animation-duration: 850ms;
  164. -moz-animation-iteration-count: 1;
  165. -moz-animation-timing-function: step-start;
  166. -moz-animation-fill-mode: forwards;
  167. }
  168.  
  169. @-webkit-keyframes boy-rotate {
  170. 0% {
  171. background-position: -603px -291px;
  172. }
  173. 16.7% {
  174. background-position: -150px -0px;
  175. }
  176. 33.4% {
  177. background-position: -453px -291px;
  178. }
  179. 50.1% {
  180. background-position: -0px -0px;
  181. }
  182. 66.8% {
  183. background-position: -903px -291px;
  184. }
  185. 83.5% {
  186. background-position: -753px -291px;
  187. }
  188. 100% {
  189. background-position: -603px -291px;
  190. }
  191. }
  192.  
  193. @-moz-keyframes boy-rotate {
  194. 0% {
  195. /*background-position: -603px -291px;*/
  196. }
  197. 16.7% {
  198. background-position: -150px -0px;
  199. }
  200. 33.4% {
  201. background-position: -453px -291px;
  202. }
  203. 50.1% {
  204. background-position: -0px -0px;
  205. }
  206. 66.8% {
  207. background-position: -903px -291px;
  208. }
  209. 83.5% {
  210. background-position: -753px -291px;
  211. }
  212. 100% {
  213. background-position: -603px -291px;
  214. }
  215. }
  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. bottom: 0;
  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. .c_background_middle {
  18. width: 100%;
  19. height: 13.1%;
  20. background-image: url("http://img1.sycdn.imooc.com//55ade1b3000135c114410118.png");
  21. background-size: 100% 100%;
  22. }
  23.  
  24. .c_background_botton {
  25. width: 100%;
  26. height: 15.3%;
  27. background-image: url("http://img1.sycdn.imooc.com//55ade1c30001db5d14410138.png");
  28. background-size: 100% 100%;
  29. }
  30.  
  31. /*小女孩*/
  32.  
  33. .girl {
  34. background: url(http://img.mukewang.com/55ade30d000100dc10570291.png) -755px -0px no-repeat;
  35. position: absolute;
  36. right: 40%;
  37. top: 37%;
  38. width: 151px;
  39. height: 291px;
  40. }
  41.  
  42. .girl-rotate {
  43. -webkit-animation-name: girl-rotate;
  44. -webkit-animation-duration: 850ms;
  45. -webkit-animation-iteration-count: 1;
  46. -webkit-animation-timing-function: step-start;
  47. -webkit-animation-fill-mode: forwards;
  48. -moz-animation-name: girl-rotate;
  49. -moz-animation-duration: 850ms;
  50. -moz-animation-iteration-count: 1;
  51. -moz-animation-timing-function: step-start;
  52. -moz-animation-fill-mode: forwards;
  53. }
  54.  
  55. @-webkit-keyframes girl-rotate {
  56. 0% {
  57. background-position: -604px -0px;
  58. }
  59. 16.7% {
  60. background-position: -151px -0px;
  61. }
  62. 33.4% {
  63. background-position: -906px -0px;
  64. }
  65. 50.1% {
  66. background-position: -0px -0px;
  67. }
  68. 66.8% {
  69. background-position: -302px -0px;
  70. }
  71. 83.5% {
  72. background-position: -453px -0px;
  73. }
  74. 100% {
  75. background-position: -604px -0px;
  76. }
  77. }
  78.  
  79. @-moz-keyframes girl-rotate {
  80. 0% {
  81. /*background-position: -604px -0px;*/
  82. }
  83. 16.7% {
  84. background-position: -151px -0px;
  85. }
  86. 33.4% {
  87. background-position: -906px -0px;
  88. }
  89. 50.1% {
  90. background-position: -0px -0px;
  91. }
  92. 66.8% {
  93. background-position: -302px -0px;
  94. }
  95. 83.5% {
  96. background-position: -453px -0px;
  97. }
  98. 100% {
  99. background-position: -604px -0px;
  100. }
  101. }
  102. /*桥*/
  103.  
  104. .bridge-bottom {
  105. position: absolute;
  106. width: 41%;
  107. height: 24%;
  108. left: 29.5%;
  109. top: 76%;
  110. overflow: hidden;
  111. /* -webkit-transform:perspective(8px) rotateX(.8deg); */
  112. }
  113. /*波浪水布局*/
  114.  
  115. .water {
  116. width: 100%;
  117. height: 100%;
  118. }
  119.  
  120. .water_1,
  121. .water_2,
  122. .water_3,
  123. .water_4 {
  124. width: 100%;
  125. position: absolute;
  126. height: 50%;
  127. -webkit-animation-name: shake;
  128. -webkit-animation-duration: 40s;
  129. -webkit-animation-direction: alternate;
  130. -webkit-anination-timing-function: linear;
  131. -webkit-animation-iteration-count: infinite;
  132. -moz-animation-name: shake;
  133. -moz-animation-duration: 40s;
  134. -moz-animation-direction: alternate;
  135. -moz-anination-timing-function: linear;
  136. -moz-animation-iteration-count: infinite;
  137. }
  138.  
  139. .water_1 {
  140. width: 131px;
  141. height: 15px;
  142. top: 13%;
  143. left: 35%;
  144. background: url(http://img.mukewang.com/55ade1e000010f2908540027.png) -261px -0px no-repeat;
  145. }
  146.  
  147. .water_2 {
  148. width: 161px;
  149. height: 9px;
  150. top: 25%;
  151. left: 45%;
  152. background: url(http://img.mukewang.com/55ade1e000010f2908540027.png) -693px -0px no-repeat;
  153. -webkit-animation-delay: 2s;
  154. -moz-animation-delay: 2s;
  155. }
  156.  
  157. .water_3 {
  158. width: 261px;
  159. height: 29px;
  160. top: 50%;
  161. left: 15%;
  162. background: url(http://img.mukewang.com/55ade1e000010f2908540027.png) -0px -0px no-repeat;
  163. -webkit-animation-delay: 1s;
  164. -moz-animation-delay: 1s;
  165. }
  166.  
  167. .water_4 {
  168. width: 301px;
  169. height: 12px;
  170. top: 70%;
  171. left: 30%;
  172. background: url(http://img.mukewang.com/55ade1e000010f2908540027.png) -392px -0px no-repeat;
  173. -webkit-animation-delay: 3s;
  174. -moz-animation-delay: 3s;
  175. }
  176.  
  177. @-webkit-keyframes shake {
  178. 0%, 100% {
  179. -webkit-transform: translate3d(0, 0, 0);
  180. }
  181. 10%,
  182. 30%,
  183. 50%,
  184. 70%,
  185. 90% {
  186. -webkit-transform: translate3d(-30px, 0px, 0);
  187. }
  188. 20%,
  189. 40%,
  190. 60%,
  191. 80% {
  192. -webkit-transform: translate3d(30px, 0px, 0);
  193. }
  194. }
  195.  
  196. @-moz-keyframes shake {
  197. 0%, 100% {
  198. -moz-transform: translate3d(0, 0, 0);
  199. }
  200. 10%,
  201. 30%,
  202. 50%,
  203. 70%,
  204. 90% {
  205. -moz-transform: translate3d(-30px, 0px, 0);
  206. }
  207. 20%,
  208. 40%,
  209. 60%,
  210. 80% {
  211. -moz-transform: translate3d(30px, 0px, 0);
  212. }
  213. }
  214.  
  215. /*星星*/
  216.  
  217. .stars {
  218. width: 100%;
  219. height: 100%;
  220. position: absolute;
  221. }
  222.  
  223. .stars > li {
  224. position: absolute;
  225. width: 30px;
  226. height: 31px;
  227. background-image: url("http://img1.sycdn.imooc.com//55ade1fe00016b8900300031.png");
  228. -webkit-animation-name: flash;
  229. -webkit-animation-timing-function: ease-in-out;
  230. -webkit-animation-iteration-count: infinite;
  231. -webkit-animation-direction: alternate;
  232. -moz-animation-name: flash;
  233. -moz-animation-timing-function: ease-in-out;
  234. -moz-animation-iteration-count: infinite;
  235. -moz-animation-direction: alternate;
  236. }
  237.  
  238. .stars1 {
  239. top: 20%;
  240. left: 30%;
  241. -webkit-animation-duration: 5s;
  242. -moz-animation-duration: 5s;
  243. }
  244.  
  245. .stars2 {
  246. top: 15%;
  247. left: 20%;
  248. -webkit-animation-duration: 20s;
  249. -moz-animation-duration: 20s;
  250. }
  251.  
  252. .stars3 {
  253. top: 25%;
  254. left: 85%;
  255. -webkit-animation-duration: 15s;
  256. -moz-animation-duration: 15s;
  257. }
  258.  
  259. .stars4 {
  260. top: 30%;
  261. left: 70%;
  262. -webkit-animation-duration: 25s;
  263. -moz-animation-duration: 25s;
  264. }
  265.  
  266. .stars5 {
  267. top: 25%;
  268. left: 20%;
  269. -webkit-animation-duration: 30s;
  270. -moz-animation-duration: 30s;
  271. }
  272.  
  273. .stars6 {
  274. top: 10%;
  275. left: 65%;
  276. -webkit-animation-duration: 10s;
  277. -moz-animation-duration: 10s;
  278. }
  279.  
  280. @-webkit-keyframes flash {
  281. 0%, 50%, 100% {
  282. opacity: 1;
  283. }
  284. 25%,
  285. 75% {
  286. opacity: 0;
  287. }
  288. }
  289.  
  290. @-moz-keyframes flash {
  291. 0%, 50%, 100% {
  292. opacity: 1;
  293. }
  294. 25%,
  295. 75% {
  296. opacity: 0;
  297. }
  298. }
  299.  
  300. /*文字效果*/
  301.  
  302. .logo {
  303. width: 185px;
  304. height: 81px;
  305. background-image: url(http://img.mukewang.com/55ade2110001708401850081.png);
  306. z-index: 999999;
  307. position: absolute;
  308. left: 50%;
  309. margin-left: -92.5px;
  310. top: 30px;
  311. display: none;
  312. }
  313.  
  314. .logolightSpeedIn {
  315. display: block;
  316. -webkit-animation-name: lightSpeedIn;
  317. -webkit-animation-timing-function: ease-out;
  318. -webkit-animation-duration: 1s;
  319. -moz-animation-name: lightSpeedIn;
  320. -moz-animation-timing-function: ease-out;
  321. -moz-animation-duration: 1s;
  322. }
  323.  
  324. @-webkit-keyframes lightSpeedIn {
  325. 0% {
  326. -webkit-transform: translate3d(100%, 0, 0) skewX(-30deg);
  327. opacity: 0;
  328. }
  329. 60% {
  330. -webkit-transform: skewX(20deg);
  331. opacity: 1;
  332. }
  333. 80% {
  334. -webkit-transform: skewX(-5deg);
  335. opacity: 1;
  336. }
  337. 100% {
  338. -webkit-transform: none;
  339. opacity: 1;
  340. }
  341. }
  342.  
  343. @-moz-keyframes lightSpeedIn {
  344. 0% {
  345. -moz-transform: translate3d(100%, 0, 0) skewX(-30deg);
  346. opacity: 0;
  347. }
  348. 60% {
  349. -moz-transform: skewX(20deg);
  350. opacity: 1;
  351. }
  352. 80% {
  353. -moz-transform: skewX(-5deg);
  354. opacity: 1;
  355. }
  356. 100% {
  357. -moz-transform: none;
  358. opacity: 1;
  359. }
  360. }
  361.  
  362. .logoshake {
  363. -webkit-animation-name: logoshake;
  364. -webkit-animation-duration: 0.5s;
  365. -moz-animation-name: logoshake;
  366. -moz-animation-duration: 0.5s;
  367. }
  368.  
  369. @-webkit-keyframes logoshake {
  370. /* 补充代码使logo产生左右晃动效果 */
  371. }
  372.  
  373. @-moz-keyframes logoshake {
  374. /* 补充代码使logo产生左右晃动效果 */
  375. }
下一节