10-19-box-animation.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <script src="js/modernizr.js"></script>
  7. <title>Box animation – CSS keyframe animations</title>
  8. <style>
  9. body {
  10. background-color: #663399;
  11. margin: 2em;
  12. }
  13. .logo {
  14. color: #fff;
  15. font-family: Helvetica Neue, Arial, sans-serif;
  16. font-size: 2em;
  17. margin: 1em 0;
  18. }
  19. .logo-box {
  20. margin-left: -.15em;
  21. }
  22. .logo-model {
  23. display: inline-block;
  24. font-weight: 400;
  25. opacity: .6;
  26. }
  27. /**
  28. * Note: we've simplified the prefixed syntax down to just using
  29. * the webkit-prefixed version (which covers most browsers in use today)
  30. * apart from the standard unprefixed syntax.
  31. */
  32. .box-outer {
  33. display: inline-block;
  34. -webkit-animation: shift 4.5s 1s steps(3, start) backwards;
  35. animation: shift 4.5s 1s steps(3, start) backwards;
  36. }
  37. .box-inner {
  38. display: inline-block;
  39. width: .74em;
  40. height: .74em;
  41. background-color: #fff;
  42. -webkit-animation: roll 1.5s 1s 3 linear backwards;
  43. animation: roll 1.5s 1s 3 linear backwards;
  44. -webkit-transform-origin: bottom right;
  45. transform-origin: bottom right;
  46. }
  47. /* for older webkit-based browsers: */
  48. @-webkit-keyframes roll {
  49. from {
  50. -webkit-transform: translateX(-100%);
  51. -webkit-animation-timing-function: ease-in-out;
  52. }
  53. 20% {
  54. -webkit-transform: translateX(-100%) skewX(15deg);
  55. }
  56. 28% {
  57. -webkit-transform: translateX(-100%) skewX(0deg);
  58. -webkit-animation-timing-function: ease-out;
  59. }
  60. 45% {
  61. -webkit-transform: translateX(-100%) skewX(-5deg) rotate(20deg) scaleY(1.1);
  62. -webkit-animation-timing-function: ease-in-out;
  63. }
  64. 50% {
  65. -webkit-transform: translateX(-100%) rotate(45deg) scaleY(1.1);
  66. -webkit-animation-timing-function: ease-in;
  67. }
  68. 60% {
  69. -webkit-transform: translateX(-100%) rotate(90deg);
  70. }
  71. 65% {
  72. -webkit-transform: translateX(-100%) rotate(90deg) skewY(10deg);
  73. }
  74. 70% {
  75. -webkit-transform: translateX(-100%) rotate(90deg) skewY(0deg);
  76. }
  77. 100% {
  78. -webkit-transform: translateX(-100%) rotate(90deg);
  79. }
  80. }
  81. /* standard syntax: */
  82. @keyframes roll {
  83. from {
  84. transform: translateX(-100%);
  85. animation-timing-function: ease-in-out;
  86. }
  87. 20% {
  88. transform: translateX(-100%) skewX(15deg);
  89. }
  90. 28% {
  91. transform: translateX(-100%) skewX(0deg);
  92. animation-timing-function: ease-out;
  93. }
  94. 45% {
  95. transform: translateX(-100%) skewX(-5deg) rotate(20deg) scaleY(1.1);
  96. animation-timing-function: ease-in-out;
  97. }
  98. 50% {
  99. transform: translateX(-100%) rotate(45deg) scaleY(1.1);
  100. animation-timing-function: ease-in;
  101. }
  102. 60% {
  103. transform: translateX(-100%) rotate(90deg);
  104. }
  105. 65% {
  106. transform: translateX(-100%) rotate(90deg) skewY(10deg);
  107. }
  108. 70% {
  109. transform: translateX(-100%) rotate(90deg) skewY(0deg);
  110. }
  111. to {
  112. transform: translateX(-100%) rotate(90deg);
  113. }
  114. }
  115. @-webkit-keyframes shift {
  116. from {
  117. -webkit-transform: translateX(-300%);
  118. }
  119. }
  120. @keyframes shift {
  121. from {
  122. transform: translateX(-300%);
  123. }
  124. }
  125. </style>
  126. </head>
  127. <body>
  128. <h1 class="logo">
  129. <!-- This is the box we are animating -->
  130. <span class="box-outer"><span class="box-inner"></span></span>
  131. <span class="logo-box">Box</span><span class="logo-model">model</span>
  132. </h1>
  133. </body>
  134. </html>