一、翻牌效果

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title>3D动画</title>
  6. <style type="text/css">
  7. body, div {
  8. padding: 0;
  9. margin: 0;
  10. }
  11. .container {
  12. position: absolute;
  13. top: 50%;
  14. left: 50%;
  15. margin-left: -177.5px;
  16. margin-top: -250px;
  17. width: 355px;
  18. height: 500px;
  19. perspective: 1000px;
  20. }
  21. .out_box {
  22. position: relative;
  23. height: 500px;
  24. width: 355px;
  25. transform-style: preserve-3d;
  26. transition: 0.5s;
  27. backface-visibility: hidden;
  28. }
  29. .out_box div {
  30. position: absolute;
  31. left: 0;
  32. top: 0;
  33. width: 100%;
  34. height: 100%;
  35. backface-visibility: hidden;
  36. }
  37. .out_box div.front_box {
  38. background: url("puke-back.png") no-repeat;
  39. background-size: 100% 100%;
  40. z-index: 2;
  41. }
  42. .out_box div.back_box {
  43. background: url("puke-k.png") no-repeat;
  44. background-size: 100% 100%;
  45. z-index: 1;
  46. transform: rotateY(180deg);
  47. }
  48. .container:hover .out_box {
  49. transform: rotateY(180deg);
  50. }
  51. .container:hover .back_box {
  52. z-index: 3;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <div class="container">
  58. <div class="out_box">
  59. <div class="front_box"></div>
  60. <div class="back_box"></div>
  61. </div>
  62. </div>
  63. </body>
  64. </html>

翻牌效果图

puke-back.pngpuke-k.png

二、钟摆

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style type="text/css">
  7. body, div {
  8. margin: 0;
  9. padding: 0;
  10. }
  11. .box {
  12. margin: 20px auto;
  13. width: 120px;
  14. height: 300px;
  15. background: url("zhongbai.png") no-repeat;
  16. /*设置运动的原点为顶部中间的位置,这样动画都围绕这个点来实现运动*/
  17. -webkit-transform-origin: top center;
  18. transform-origin: top center;
  19. /*设置运动的初始位置-->左边旋转45deg位置*/
  20. -webkit-transform: rotate(45deg);
  21. transform: rotate(45deg);
  22. /*设置css3运动动画*/
  23. -webkit-animation: move 1s ease infinite;
  24. animation: move 1s ease infinite;
  25. }
  26. /*设置动画运动的关键帧*/
  27. @-webkit-keyframes move {
  28. 0%, 100% {
  29. -webkit-transform: rotate(45deg);
  30. transform: rotate(45deg);
  31. }
  32. 50% {
  33. -webkit-transform: rotate(-45deg);
  34. transform: rotate(-45deg);
  35. }
  36. }
  37. @keyframes move {
  38. 0%, 100% {
  39. -webkit-transform: rotate(45deg);
  40. transform: rotate(45deg);
  41. }
  42. 50% {
  43. -webkit-transform: rotate(-45deg);
  44. transform: rotate(-45deg);
  45. }
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <div class="box"></div>
  51. </body>
  52. </html>

钟摆效果图

zhongbai.png