先说一个今天在开发过程中遇到的问题。

对同一个元素同时使用transform和animation,transform会失效。
解决办法:就是在这个元素的外层再加一层div,对外层的div进行transform,对内层div进行animation就可以解决了。

CSS常用动画库

animates.css
github地址 https://github.com/daneden/animate.c查看演示地址 https://daneden.github.io/animate.css/

Hover.css http://ianlunn.github.io/Hover/

Magic动画库制作CSS3动画特效 http://www.17sucai.com/pins/demoshow/10001

CSS动画简介 http://www.ruanyifeng.com/blog/2014/02/css_transition_and_animation.html

一,CSS常用代码

  1. border-radius: 6px;
  2. border-radius: 50%;
  3. box-shadow: 1px 1px 1px #666;
  4. .text-style {
  5. text-shadow: 5px 5px 5px #FF0000;
  6. word-wrap: break-word;
  7. text-overflow: ellipsis;
  8. }
  9. .transform {
  10. transform: translate(50px, 100px);
  11. transform: rotate(30deg);
  12. transform: scale(2, 4);
  13. transform: skew(30deg, 20deg);
  14. transform: matrix(0.866, 0.5, -0.5, 0.866, 0, 0);
  15. transform: rotateX(120deg);
  16. transform: rotateY(130deg);
  17. -ms-transform: rotateY(130deg);
  18. -webkit-transform: rotateY(130deg);
  19. -o-transform: rotateY(130deg);
  20. -moz-transform: rotateY(130deg);
  21. }
  22. .linear-gradient {
  23. width: 400px;
  24. height: 60px;
  25. background-color: #063053;
  26. background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.32, #063053), color-stop(0.66, #395873), color-stop(0.83, #5c7c99));
  27. background-image: linear-gradient(#063053, #395873, #5c7c99);
  28. }
  29. background-image: linear-gradient(180deg, #5e00b7, #d76c00);
  30. background-image: linear-gradient(red, green, blue, purple, orange);
  31. .gradient1 {
  32. width: 400px;
  33. height: 400px;
  34. background-color: #4B770A;
  35. background-image: -webkit-gradient(radial,
  36. 50% 200, 1,
  37. 50% 200, 200,
  38. from(rgba(255, 255, 255, 0.3)),
  39. to(rgba(255, 255, 255, 0)));
  40. }

二,单个能直接拿来用的CSS 3.0 动画

(一),hover时的动画

1,360°旋转 修改rotate(旋转度数)
  1. <div class="transform1 box">div</div>
  2. .box {
  3. width: 100px;
  4. height: 100px;
  5. background: #fac;
  6. }
  7. .transform1 {
  8. transition: All 0.4s ease-in-out;
  9. -webkit-transition: All 0.4s ease-in-out;
  10. -moz-transition: All 0.4s ease-in-out;
  11. -o-transition: All 0.4s ease-in-out;
  12. }
  13. .transform1:hover {
  14. transform: rotate(360deg);
  15. -webkit-transform: rotate(360deg);
  16. -moz-transform: rotate(360deg);
  17. -o-transform: rotate(360deg);
  18. -ms-transform: rotate(360deg);
  19. }

2,放大 修改scale(放大的值)
  1. <div class="transform2 box">div</div>
  2. .box {
  3. width: 100px;
  4. height: 100px;
  5. background: #fac;
  6. }
  7. .transform2 {
  8. transition: All 0.4s ease-in-out;
  9. -webkit-transition: All 0.4s ease-in-out;
  10. -moz-transition: All 0.4s ease-in-out;
  11. -o-transition: All 0.4s ease-in-out;
  12. }
  13. .transform2:hover {
  14. transform: scale(1.2);
  15. -webkit-transform: scale(1.2);
  16. -moz-transform: scale(1.2);
  17. -o-transform: scale(1.2);
  18. -ms-transform: scale(1.2);
  19. }

3,旋转放大 修改rotate(旋转度数) scale(放大值)
  1. <div class="transform3 box">div</div>
  2. .box {
  3. width: 100px;
  4. height: 100px;
  5. background: #fac;
  6. }
  7. .transform3 {
  8. transition: All 0.4s ease-in-out;
  9. -webkit-transition: All 0.4s ease-in-out;
  10. -moz-transition: All 0.4s ease-in-out;
  11. -o-transition: All 0.4s ease-in-out;
  12. }
  13. .transform3:hover {
  14. transform: rotate(360deg) scale(1.2);
  15. -webkit-transform: rotate(360deg) scale(1.2);
  16. -moz-transform: rotate(360deg) scale(1.2);
  17. -o-transform: rotate(360deg) scale(1.2);
  18. -ms-transform: rotate(360deg) scale(1.2);
  19. }

4,上下左右移动 修改translate(x轴,y轴)
  1. <div class="transform4 box">div</div>
  2. .box {
  3. width: 100px;
  4. height: 100px;
  5. background: #fac;
  6. }
  7. .transform4 {
  8. transition: All 0.4s ease-in-out;
  9. -webkit-transition: All 0.4s ease-in-out;
  10. -moz-transition: All 0.4s ease-in-out;
  11. -o-transition: All 0.4s ease-in-out;
  12. }
  13. .transform4:hover {
  14. transform: translate(0, -10px);
  15. -webkit-transform: translate(0, -10px);
  16. -moz-transform: translate(0, -10px);
  17. -o-transform: translate(0, -10px);
  18. -ms-transform: translate(0, -10px);
  19. }

以上动画通过用SCSS改造
  1. @mixin dz($time:0.25s){
  2. -webkit-transition: all $time ease-in-out;
  3. -moz-transition: all $time ease-in-out;
  4. -o-transition: all $time ease-in-out;
  5. -ms-transition: all $time ease-in-out;
  6. transition: all $time ease-in-out;
  7. }
  8. @mixin xz($deg:360){
  9. transform:rotate($deg+deg);
  10. -webkit-transform:rotate($deg+deg);
  11. -moz-transform:rotate($deg+deg);
  12. -o-transform:rotate($deg+deg);
  13. -ms-transform:rotate($deg+deg);
  14. }
  15. @minxin fd($s1:1.2){
  16. transform:scale($s1);
  17. -webkit-transform:scale($s1);
  18. -moz-transform:scale($s1);
  19. -o-transform:scale($s1);
  20. -ms-transform:scale($s1);
  21. }
  22. @mixin xzfd($deg:360,$s1:1.2){
  23. transform:rotate($deg+deg) scale($s1);
  24. -webkit-transform:rotate($deg+deg) scale($s1);
  25. -moz-transform:rotate($deg+deg) scale($s1);
  26. -o-transform:rotate($deg+deg) scale($s1);
  27. -ms-transform:rotate($deg+deg) scale($s1);
  28. }
  29. @mixin yd($s1:0,$s2:0){
  30. transform:translate($s1,$s2);
  31. -webkit-transform:translate($s1,$s2);
  32. -moz-transform:translate($s1,$s2);
  33. -o-transform:translate($s1,$s2);
  34. -ms-transform:translate($s1,$s2);
  35. }
  36. 使用方法
  37. @include dz();
  38. &:hover {
  39. @include yd(-10px,-10px);
  40. }
  41. }

5,鼠标悬停抖动效果

常用动画 - 图1

WechatIMG63.jpeg

  1. <div class="lanren">Hover Me</div>
  1. .lanren {
  2. margin: 100px auto;
  3. width: 100px;
  4. text-align: center;
  5. height: 40px;
  6. line-height: 40px;
  7. border: 1px solid #CCC;
  8. border-radius: 2px;
  9. }
  10. .lanren:hover {
  11. animation: shake 0.82s cubic-bezier(.36, .07, .19, .97) both;
  12. transform: translate3d(0, 0, 0);
  13. backface-visibility: hidden;
  14. perspective: 1000px;
  15. }
  16. @keyframes shake {
  17. 10%, 90% {
  18. transform: translate3d(-1px, 0, 0);
  19. }
  20. 20%, 80% {
  21. transform: translate3d(2px, 0, 0);
  22. }
  23. 30%, 50%, 70% {
  24. transform: translate3d(-4px, 0, 0);
  25. }
  26. 40%, 60% {
  27. transform: translate3d(4px, 0, 0);
  28. }
  29. }

6,圆形边框hover动画

常用动画 - 图2

circle.png

html

  1. <div class="svg-wrapper">
  2. <svg height="166" width="166" xmlns="http://www.w3.org/2000/svg">
  3. <circle cx="83" fill="#f5f5f5" cy="83" r="81" class="shape" height="166" width="166"></circle>
  4. <div class="text">circle</div>
  5. </svg>
  6. </div>

css

  1. .svg-wrapper {
  2. position: relative;
  3. transform: translateY(-50%);
  4. margin: 100px 100px;
  5. width: 164px;
  6. }
  7. .shape {
  8. stroke-dasharray: 0 540;
  9. stroke-dashoffset: -474;
  10. stroke-width: 1px;
  11. stroke: #19f6e8;
  12. border-radius: 100%;
  13. transition: stroke-width 1s, stroke-dashoffset 1s, stroke-dasharray 1s;
  14. }
  15. .text {
  16. font-family: 'Roboto Condensed';
  17. font-size: 22px;
  18. line-height: 164px;
  19. letter-spacing: 8px;
  20. height:164px;
  21. color: #b03e00;
  22. top: 0;
  23. position: absolute;
  24. left:0;
  25. width:164px;
  26. text-align: center;
  27. }
  28. .svg-wrapper:hover .shape {
  29. stroke-width: 2px;
  30. stroke-dashoffset: 0;
  31. stroke-dasharray: 760;
  32. border-radius: 100%;
  33. }

7,渐变按钮

常用动画 - 图3

WechatIMG65.jpeg

html

  1. <div class="myButton">myButton</div>

css

  1. .myButton {
  2. width: 300px;
  3. height: 60px;
  4. line-height: 60px;
  5. text-align: center;
  6. -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
  7. -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
  8. box-shadow:inset 0px 1px 0px 0px #ffffff;
  9. background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf));
  10. background:-moz-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
  11. background:-webkit-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
  12. background:-o-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
  13. background:-ms-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
  14. background:linear-gradient(to bottom, #ededed 5%, #dfdfdf 100%);
  15. filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf',GradientType=0);
  16. background-color:#ededed;
  17. -moz-border-radius:6px;
  18. -webkit-border-radius:6px;
  19. border-radius:6px;
  20. border:1px solid #dcdcdc;
  21. display:inline-block;
  22. cursor:pointer;
  23. color:#777777;
  24. font-family:arial;
  25. font-size:30px;
  26. font-weight:bold;
  27. padding:6px 24px;
  28. text-decoration:none;
  29. text-shadow:0px 1px 0px #ffffff;
  30. margin-top: 100px;
  31. }
  32. .myButton:hover {
  33. background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed));
  34. background:-moz-linear-gradient(top, #dfdfdf 5%, #ededed 100%);
  35. background:-webkit-linear-gradient(top, #dfdfdf 5%, #ededed 100%);
  36. background:-o-linear-gradient(top, #dfdfdf 5%, #ededed 100%);
  37. background:-ms-linear-gradient(top, #dfdfdf 5%, #ededed 100%);
  38. background:linear-gradient(to bottom, #dfdfdf 5%, #ededed 100%);
  39. filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed',GradientType=0);
  40. background-color:#dfdfdf;
  41. }
  42. .myButton:active {
  43. position:relative;
  44. top:1px;
  45. }

(二),元素切入时的动画

元素宽度100%,高度自定义。另外,还需要根据不同屏幕宽度来做适配,屏幕翻转的时候重新适配一次。
适配的js代码

  1. <script type="text/javascript">
  2. //适配函数
  3. function reset() {
  4. var wrapo = document.getElementById('wrap'),
  5. clientW = document.documentElement.clientWidth || document.body.clientWidth,
  6. designw = 640,
  7. scaleRate = clientW / designw;
  8. wrapo.style.cssText = "-webkit-transform-origin:0 0;transform-origin:0 0;webkit-transform:scale(" + scaleRate + ");transform:scale(" + scaleRate + ");"
  9. }
  10. //初始进来执行一次适配
  11. reset();
  12. //当屏幕旋转的时候,再次执行一次适配
  13. window.addEventListener('resize', function () {
  14. setTimeout(function () {
  15. reset();
  16. }, 100);
  17. }, false)
  18. </script>

html代码

  1. <div id="wrap">
  2. <div class="up_down">从上往下透明切入</div>
  3. <div class="down_up">从下往上透明切入</div>
  4. <div class="right_left">从右往左透明切入</div>
  5. <div class="left_right">从左往右透明切入</div>
  6. <div class="opacityan">透明进入</div>
  7. <div class="rotatean">旋转</div>
  8. <div class="scale_rotate">缩放透明入场</div>
  9. <div class="flip_warp">
  10. <div class="flip">3D翻转</div>
  11. </div>
  12. <div class="watering_opean">
  13. <div class="watering"></div>
  14. </div>
  15. </div>

公用css代码

  1. #wrap {
  2. width: 640px;
  3. overflow: hidden;
  4. }
  5. #wrap > div {
  6. width: 100%;
  7. height: 86px;
  8. line-height: 86px;
  9. font-size: 30px;
  10. text-align: center;
  11. opacity: 0;
  12. }

1,从左往右透明切入

  1. @-webkit-keyframes lran {
  2. 0% {
  3. -webkit-transform: translateX(-100%);
  4. opacity: 0;
  5. }
  6. 100% {
  7. -webkit-transform: translateX(0);
  8. opacity: 1;
  9. }
  10. }
  11. @keyframes lran {
  12. 0% {
  13. transform: translateX(-100%);
  14. opacity: 0;
  15. }
  16. 100% {
  17. transform: translateX(0);
  18. opacity: 1;
  19. }
  20. }
  21. .left_right {
  22. background: gray;
  23. -webkit-animation: lran 0.6s 1 1.8s forwards;
  24. animation: lran 0.6s 1 1.8s forwards;
  25. }

2,从右往左透明切入

  1. @-webkit-keyframes rlan {
  2. 0% {
  3. -webkit-transform: translateX(100%);
  4. opacity: 0;
  5. }
  6. 100% {
  7. -webkit-transform: translateX(0);
  8. opacity: 1;
  9. }
  10. }
  11. @keyframes rlan {
  12. 0% {
  13. transform: translateX(100%);
  14. opacity: 0;
  15. }
  16. 100% {
  17. transform: translateX(0);
  18. opacity: 1;
  19. }
  20. }
  21. .right_left {
  22. background: green;
  23. -webkit-animation: rlan 0.6s 1 1.2s forwards;
  24. animation: rlan 0.6s 1 1.2s forwards;
  25. }

3,从下往上透明切入

  1. @-webkit-keyframes btan {
  2. 0% {
  3. -webkit-transform: translateY(100%);
  4. opacity: 0;
  5. }
  6. 100% {
  7. -webkit-transform: translateY(0);
  8. opacity: 1;
  9. }
  10. }
  11. @keyframes btan {
  12. 0% {
  13. transform: translateY(100%);
  14. opacity: 0;
  15. }
  16. 100% {
  17. transform: translateY(0);
  18. opacity: 1;
  19. }
  20. }
  21. .down_up {
  22. background: blue;
  23. -webkit-animation: btan 0.6s 1 0.6s forwards;
  24. animation: btan 0.6s 1 0.6s forwards;
  25. }

4,从上往下透明切入

  1. @-webkit-keyframes tban {
  2. 0% {
  3. -webkit-transform: translateY(-100%);
  4. opacity: 0;
  5. }
  6. 100% {
  7. -webkit-transform: translateY(0);
  8. opacity: 1;
  9. }
  10. }
  11. @keyframes tban {
  12. 0% {
  13. transform: translateY(-100%);
  14. opacity: 0;
  15. }
  16. 100% {
  17. transform: translateY(0);
  18. opacity: 1;
  19. }
  20. }
  21. .up_down {
  22. background: red;
  23. -webkit-animation: tban 0.6s 1 0s forwards;
  24. animation: tban 0.6s 1 0s forwards;
  25. }

5,旋转动画

  1. @-webkit-keyframes rotaan {
  2. 0% {
  3. -webkit-transform: rotateZ(0deg);
  4. opacity: 0;
  5. }
  6. 100% {
  7. -webkit-transform: rotateZ(360deg);
  8. opacity: 1;
  9. }
  10. }
  11. @keyframes rotaan {
  12. 0% {
  13. transform: rotateZ(0deg);
  14. opacity: 0;
  15. }
  16. 100% {
  17. transform: rotateZ(360deg);
  18. opacity: 1;
  19. }
  20. }
  21. .rotatean {
  22. background: yellow;
  23. -webkit-animation: rotaan 0.6s 1 3s forwards;
  24. animation: rotaan 0.6s 1 3s forwards;
  25. }

6,缩放透明入场

  1. @-webkit-keyframes scalean {
  2. 0% {
  3. -webkit-transform: scale(5);
  4. opacity: 0;
  5. }
  6. 100% {
  7. -webkit-transform: scale(1);
  8. opacity: 1;
  9. }
  10. }
  11. @keyframes scalean {
  12. 0% {
  13. transform: scale(5);
  14. opacity: 0;
  15. }
  16. 100% {
  17. transform: scale(1);
  18. opacity: 1;
  19. }
  20. }
  21. .scale_rotate {
  22. background: black;
  23. color: #fff;
  24. -webkit-animation: scalean 0.6s 1 3.6s forwards;
  25. animation: scalean 0.6s 1 3.6s forwards;
  26. }

7,透明进入

  1. @-webkit-keyframes opean {
  2. 0% {
  3. opacity: 0;
  4. }
  5. 100% {
  6. opacity: 1;
  7. }
  8. }
  9. @keyframes opean {
  10. 0% {
  11. opacity: 0;
  12. }
  13. 100% {
  14. opacity: 1;
  15. }
  16. }
  17. .opacityan {
  18. background: purple;
  19. -webkit-animation: opean 0.6s 1 2.4s forwards;
  20. animation: opean 0.6s 1 2.4s forwards;
  21. }
  22. #wrap .flip_warp {
  23. -webkit-animation: opean 0.4s 1 4.2s forwards;
  24. animation: opean 0.4s 1 4.2s forwards;
  25. -webkit-perspective: 800px;
  26. perspective: 800px;
  27. }
  28. #wrap .watering_opean {
  29. width: 328.7px;
  30. height: 634px;
  31. position: fixed;
  32. top: 10px;
  33. right: 10px;
  34. -webkit-animation: opean 0.4s 1 5.2s forwards;
  35. animation: opean 0.4s 1 5.2s forwards;
  36. }

8,3D翻转 ,上下两个有的时候需要结合使用

  1. @-webkit-keyframes flipan {
  2. 0% {
  3. -webkit-transform: rotateX(-180deg);
  4. }
  5. 100% {
  6. -webkit-transform: rotateX(0);
  7. }
  8. }
  9. @keyframes flipan {
  10. 0% {
  11. transform: rotateX(-180deg);
  12. }
  13. 100% {
  14. transform: rotateX(0);
  15. }
  16. }
  17. #wrap .flip {
  18. background: black;
  19. color: #fff;
  20. -webkit-transform-style: preserve-3d;
  21. transform-style: preserve-3d;
  22. -webkit-transform: rotateX(-180deg);
  23. transform: rotateX(-180deg);
  24. -webkit-animation: flipan 0.6s 1 4.4s forwards;
  25. animation: flipan 0.6s 1 4.4s forwards;
  26. }

9,序列帧动画

  1. @-webkit-keyframes wateringan {
  2. 0% {
  3. background-position: 0 0;
  4. }
  5. 100% {
  6. background-position: -3287px 0;
  7. }
  8. }
  9. @keyframes wateringan {
  10. 0% {
  11. background-position: 0 0;
  12. }
  13. 100% {
  14. background-position: -3287px 0;
  15. }
  16. }
  17. #wrap .watering {
  18. width: 328.7px;
  19. height: 634px;
  20. background: url(waterspr.png) no-repeat;
  21. -webkit-animation: wateringan 1s steps(10, end) 5.6s infinite;
  22. animation: wateringan 1s steps(10, end) 5.6s infinite;
  23. }

waterspr.png 图片如下:

常用动画 - 图4

waterspr.png

(三),加载(loading)动画

1,进度条+数字展示

常用动画 - 图5

WechatIMG64.jpeg

html

  1. <div class="loading">
  2. <div class="loading-con" id="loading-line"></div>
  3. <p class="per-num" id="loading-per">0%</p>
  4. </div>

js

  1. <script>
  2. var imgarr = [
  3. '[http://himg2.huanqiu.com/attachment2010/2012/0525/20120525042526697.jpg'](http://himg2.huanqiu.com/attachment2010/2012/0525/20120525042526697.jpg'),
  4. '[http://www.chinanews.com/cr/2015/1119/2634365829.jpg'](http://www.chinanews.com/cr/2015/1119/2634365829.jpg'),
  5. '[http://www.cssn.cn/zt/zt_xkzt/zt_jsxzt/jsx_jjnh/nh_rtzx/201412/W020141208537235397889.jpg'](http://www.cssn.cn/zt/zt_xkzt/zt_jsxzt/jsx_jjnh/nh_rtzx/201412/W020141208537235397889.jpg'),
  6. '[http://www.cssn.cn/zt/zt_xkzt/zt_jsxzt/jsx_jjnh/nh_rtzx/201412/W020141208537235397889.jpg'](http://www.cssn.cn/zt/zt_xkzt/zt_jsxzt/jsx_jjnh/nh_rtzx/201412/W020141208537235397889.jpg'),
  7. '[http://www.xinhuanet.com/world/titlepic/111547/1115479659_title0h.jpg'](http://www.xinhuanet.com/world/titlepic/111547/1115479659_title0h.jpg'),
  8. '[http://www.redjun.com/uploads/allimg/150123/102302G57-4.jpg'](http://www.redjun.com/uploads/allimg/150123/102302G57-4.jpg'),
  9. '[http://www.gzsrex.com/Uploads/201405/53686507a525b.jpg'](http://www.gzsrex.com/Uploads/201405/53686507a525b.jpg'),
  10. '[http://pic39.nipic.com/20140316/3344588_235616333189_2.jpg'](http://pic39.nipic.com/20140316/3344588_235616333189_2.jpg') ],
  11. //要加载的图片地址,此处是直接从网上找的,模拟效果用,实现场景要换成真的
  12. loadingL = document.getElementById("loading-line"), //进度条
  13. loadingPer = document.getElementById("loading-per"); //进度值
  14. //改变进度函数
  15. function changefn(num) {
  16. loadingL.style.width = num + '%';
  17. loadingPer.innerHTML = num + '%';
  18. }
  19. function loadingfn() {
  20. var imgo = new Image(),//图像对象
  21. imglen = imgarr.length - 1,
  22. count = 0,
  23. pernum = 0;
  24. imgo.src = imgarr[count];
  25. imgo.onload = function () {
  26. count++;
  27. pernum = parseInt(count / imglen * 100);
  28. changefn(pernum);
  29. if (count == imglen) {
  30. //这里执行页面初始化工作
  31. alert('图片加载完成喽!可以进入初始化')
  32. return;
  33. }
  34. this.src = imgarr[count];
  35. };
  36. imgo.onerror = function() {
  37. //这里执行页面初始化工作
  38. alert('图片出错直接加载完成喽!可以进入初始化')
  39. };
  40. }
  41. loadingfn();
  42. </script>

css

  1. *{
  2. margin: 0;
  3. padding: 0;
  4. }
  5. .loading {
  6. width: 80%;
  7. height: 36px;
  8. background: #999;
  9. position: absolute;
  10. top: 50%;
  11. left: 50%;
  12. transform: translate(-50%, -50%);
  13. overflow: hidden;
  14. border-radius: 5px;
  15. }
  16. .loading-con {
  17. width: 0;
  18. height: 36px;
  19. background: green;
  20. }
  21. .per-num {
  22. width: 100%;
  23. height: 36px;
  24. line-height: 36px;
  25. text-align: center;
  26. color: #fff;
  27. font-size: 24px;
  28. position: absolute;
  29. top: 0;
  30. left: 0;
  31. }

2,条形元素循环动画展示

常用动画 - 图6

WechatIMG61.jpeg

html

  1. <div class="spinner1">
  2. <div class="rect1"></div>
  3. <div class="rect2"></div>
  4. <div class="rect3"></div>
  5. <div class="rect4"></div>
  6. <div class="rect5"></div>
  7. </div>

css

  1. .spinner1 {
  2. margin: 100px auto;
  3. width: 50px;
  4. height: 60px;
  5. text-align: center;
  6. font-size: 10px;
  7. border: 1px solid #eaeaea;
  8. }
  9. .spinner1 > div {
  10. background-color: #67CF22;
  11. height: 100%;
  12. width: 6px;
  13. display: inline-block;
  14. -webkit-animation: stretchdelay 1.2s infinite ease-in-out;
  15. animation: stretchdelay 1.2s infinite ease-in-out;
  16. }
  17. .spinner1 .rect2 {
  18. -webkit-animation-delay: -1.1s;
  19. animation-delay: -1.1s;
  20. }
  21. .spinner1 .rect3 {
  22. -webkit-animation-delay: -1.0s;
  23. animation-delay: -1.0s;
  24. }
  25. .spinner1 .rect4 {
  26. -webkit-animation-delay: -0.9s;
  27. animation-delay: -0.9s;
  28. }
  29. .spinner1 .rect5 {
  30. -webkit-animation-delay: -0.8s;
  31. animation-delay: -0.8s;
  32. }
  33. @-webkit-keyframes stretchdelay {
  34. 0%, 40%, 100% { -webkit-transform: scaleY(0.4) }
  35. 20% { -webkit-transform: scaleY(1.0) }
  36. }
  37. @keyframes stretchdelay {
  38. 0%, 40%, 100% {
  39. transform: scaleY(0.4);
  40. -webkit-transform: scaleY(0.4);
  41. } 20% {
  42. transform: scaleY(1.0);
  43. -webkit-transform: scaleY(1.0);
  44. }
  45. }

3,圆形并排三个缩放动画展示

常用动画 - 图7

WechatIMG60.jpeg

html

  1. <div class="spinner">
  2. <div class="bounce1"></div>
  3. <div class="bounce2"></div>
  4. <div class="bounce3"></div>
  5. </div>

css

  1. .spinner { margin: 100px auto 0;
  2. width: 150px;
  3. text-align: center;
  4. }
  5. .spinner > div {
  6. width: 30px;
  7. height: 30px;
  8. background-color: #67CF22;
  9. border-radius: 100%;
  10. display: inline-block;
  11. -webkit-animation: bouncedelay 1.4s infinite ease-in-out;
  12. animation: bouncedelay 1.4s infinite ease-in-out;
  13. -webkit-animation-fill-mode: both;
  14. animation-fill-mode: both;
  15. }
  16. .spinner .bounce1 {
  17. -webkit-animation-delay: -0.32s;
  18. animation-delay: -0.32s;
  19. }
  20. .spinner .bounce2 {
  21. -webkit-animation-delay: -0.16s;
  22. animation-delay: -0.16s;
  23. }
  24. @-webkit-keyframes bouncedelay {
  25. 0%, 80%, 100% { -webkit-transform: scale(0.0) }
  26. 40% { -webkit-transform: scale(1.0) }
  27. }
  28. @keyframes bouncedelay {
  29. 0%, 80%, 100% {
  30. transform: scale(0.0);
  31. -webkit-transform: scale(0.0);
  32. } 40% {
  33. transform: scale(1.0);
  34. -webkit-transform: scale(1.0);
  35. }
  36. }

4,圆形环绕大圆旋转动画展示

常用动画 - 图8

WechatIMG62.jpeg

html

  1. <div class="spinner">
  2. <div class="spinner-container container1">
  3. <div class="circle1"></div>
  4. <div class="circle2"></div>
  5. <div class="circle3"></div>
  6. <div class="circle4"></div>
  7. </div>
  8. <div class="spinner-container container2">
  9. <div class="circle1"></div>
  10. <div class="circle2"></div>
  11. <div class="circle3"></div>
  12. <div class="circle4"></div>
  13. </div>
  14. <div class="spinner-container container3">
  15. <div class="circle1"></div>
  16. <div class="circle2"></div>
  17. <div class="circle3"></div>
  18. <div class="circle4"></div>
  19. </div>
  20. </div>

css

  1. .spinner { margin: 100px auto;
  2. width: 20px;
  3. height: 20px;
  4. position: relative;
  5. }
  6. .container1 > div, .container2 > div, .container3 > div {
  7. width: 6px;
  8. height: 6px;
  9. background-color: #333;
  10. border-radius: 100%;
  11. position: absolute;
  12. -webkit-animation: bouncedelay 1.2s infinite ease-in-out;
  13. animation: bouncedelay 1.2s infinite ease-in-out;
  14. -webkit-animation-fill-mode: both;
  15. animation-fill-mode: both;
  16. }
  17. .spinner .spinner-container {
  18. position: absolute;
  19. width: 100%;
  20. height: 100%;
  21. }
  22. .container2 {
  23. -webkit-transform: rotateZ(45deg);
  24. transform: rotateZ(45deg);
  25. }
  26. .container3 {
  27. -webkit-transform: rotateZ(90deg);
  28. transform: rotateZ(90deg);
  29. }
  30. .circle1 { top: 0; left: 0; }
  31. .circle2 { top: 0; right: 0; }
  32. .circle3 { right: 0; bottom: 0; }
  33. .circle4 { left: 0; bottom: 0; }
  34. .container2 .circle1 {
  35. -webkit-animation-delay: -1.1s;
  36. animation-delay: -1.1s;
  37. }
  38. .container3 .circle1 {
  39. -webkit-animation-delay: -1.0s;
  40. animation-delay: -1.0s;
  41. }
  42. .container1 .circle2 {
  43. -webkit-animation-delay: -0.9s;
  44. animation-delay: -0.9s;
  45. }
  46. .container2 .circle2 {
  47. -webkit-animation-delay: -0.8s;
  48. animation-delay: -0.8s;
  49. }
  50. .container3 .circle2 {
  51. -webkit-animation-delay: -0.7s;
  52. animation-delay: -0.7s;
  53. }
  54. .container1 .circle3 {
  55. -webkit-animation-delay: -0.6s;
  56. animation-delay: -0.6s;
  57. }
  58. .container2 .circle3 {
  59. -webkit-animation-delay: -0.5s;
  60. animation-delay: -0.5s;
  61. }
  62. .container3 .circle3 {
  63. -webkit-animation-delay: -0.4s;
  64. animation-delay: -0.4s;
  65. }
  66. .container1 .circle4 {
  67. -webkit-animation-delay: -0.3s;
  68. animation-delay: -0.3s;
  69. }
  70. .container2 .circle4 {
  71. -webkit-animation-delay: -0.2s;
  72. animation-delay: -0.2s;
  73. }
  74. .container3 .circle4 {
  75. -webkit-animation-delay: -0.1s;
  76. animation-delay: -0.1s;
  77. }
  78. @-webkit-keyframes bouncedelay {
  79. 0%, 80%, 100% { -webkit-transform: scale(0.0) }
  80. 40% { -webkit-transform: scale(1.0) }
  81. }
  82. @keyframes bouncedelay {
  83. 0%, 80%, 100% {
  84. transform: scale(0.0);
  85. -webkit-transform: scale(0.0);
  86. } 40% {
  87. transform: scale(1.0);
  88. -webkit-transform: scale(1.0);
  89. }
  90. }