_mixins-animations.scss 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*--------------------------------------------------------------*/
  2. /* !## Animations */
  3. /*--------------------------------------------------------------*/
  4. // Using the mixins looks like this:
  5. // @include keyframes(move-the-object) {
  6. // 0% { left: 100px; }
  7. // 100% { left: 200px; }
  8. // }
  9. //
  10. // .object-to-animate {
  11. // @include animation('move-the-object .5s 1', 'move-the-object-again .5s 1 .5s');
  12. // }
  13. // Order from longest to shortest
  14. // If anything changes edit here!!
  15. $default-prefixes: webkit moz ms o;
  16. // Prefixer mixin
  17. // $attr: property to be prefixed (transition, transform, box-shadow), can be added via another mixin or directly
  18. // $value: value of the property
  19. // $prefixes: by default it uses those defined as default, but can be changed to those needed
  20. @mixin prefix( $attr, $value, $prefixes: $default-prefixes ) {
  21. // Output each prefixed rule
  22. @each $prefix in $prefixes {
  23. -#{ $prefix }-#{ $attr }: #{ $value };
  24. }
  25. // Non prefixed rule
  26. #{ $attr }: #{ $value };
  27. }
  28. // Multi-transition mixins
  29. //
  30. // Src: https://gist.github.com/tobiasahlin/7a421fb9306a4f518aab
  31. //
  32. // Usage: @include multitransition(width, height 0.3s ease-in-out);
  33. // Output: -webkit-transition(width 0.2s, height 0.3s ease-in-out);
  34. // transition(width 0.2s, height 0.3s ease-in-out);
  35. //
  36. // Pass in any number of transitions
  37. @mixin multitransition($transitions...) {
  38. $unfoldedTransitions: ();
  39. @each $transition in $transitions {
  40. $unfoldedTransitions: append($unfoldedTransitions, unfoldTransition($transition), comma);
  41. }
  42. -webkit-transition: $unfoldedTransitions;
  43. transition: $unfoldedTransitions;
  44. }
  45. // Unfold transition mixin
  46. @function unfoldTransition ($transition) {
  47. // Default values
  48. $property: all;
  49. $duration: .2s;
  50. $easing: null; // Browser default is ease, which is what we want
  51. $delay: null; // Browser default is 0, which is what we want
  52. $defaultProperties: ($property, $duration, $easing, $delay);
  53. // Grab transition properties if they exist
  54. $unfoldedTransition: ();
  55. @for $i from 1 through length($defaultProperties) {
  56. $p: null;
  57. @if $i <= length($transition) {
  58. $p: nth($transition, $i)
  59. } @else {
  60. $p: nth($defaultProperties, $i)
  61. }
  62. $unfoldedTransition: append($unfoldedTransition, $p);
  63. }
  64. @return $unfoldedTransition;
  65. }
  66. // Transition mixin
  67. @mixin transition( $attr, $delay, $fx ) {
  68. $value: $attr $delay $fx;
  69. @include prefix( 'transition', $value );
  70. }
  71. // example: @include transition(color, .8s, linear);
  72. // Transform mixin
  73. @mixin transform( $attr, $value ) {
  74. $property: str_insert( $attr, '()', -1 );
  75. $prop: str_insert( $property, #{ $value }, -2 );
  76. @include prefix( 'transform', $prop );
  77. }
  78. // example: @include transform(transformX, -100%);
  79. // Prefixed animations
  80. @mixin animation( $animate... ) {
  81. $max: length( $animate );
  82. $animations: '';
  83. @for $i from 1 through $max {
  84. $animations: #{ $animations + nth( $animate, $i ) };
  85. @if $i < $max {
  86. $animations: #{ $animations + ", " };
  87. }
  88. }
  89. -webkit-animation: $animations;
  90. -moz-animation: $animations;
  91. -o-animation: $animations;
  92. animation: $animations;
  93. }
  94. // Keyframes settings
  95. @mixin keyframes( $animationName ) {
  96. @-webkit-keyframes #{ $animationName } {
  97. @content;
  98. }
  99. @-moz-keyframes #{ $animationName } {
  100. @content;
  101. }
  102. @-o-keyframes #{ $animationName } {
  103. @content;
  104. }
  105. @keyframes #{ $animationName } {
  106. @content;
  107. }
  108. }
  109. @include keyframes( bounce-reveal-y ) {
  110. 0%,
  111. 100% {
  112. @include transform( scaleY, 1 ); // -webkit-transform: scaleY(1);
  113. }
  114. 50% {
  115. @include transform( scaleY, 1.1 ); // -webkit-transform: scaleY(1.1);
  116. }
  117. }
  118. @include keyframes( bounce-hide-y ) {
  119. 0%,
  120. 100% {
  121. @include transform( scaleY, 1 ); // -webkit-transform: scaleY(1);
  122. }
  123. 50% {
  124. @include transform( scaleY, .9 ); // -webkit-transform: scaleY(1.1);
  125. }
  126. }
  127. @include keyframes( bounce-reveal ) {
  128. 0%,
  129. 100% {
  130. @include transform( scale, 1 );
  131. }
  132. 33% {
  133. @include transform( scale, 1.1 );
  134. }
  135. 66% {
  136. @include transform( scale, 0.9 );
  137. }
  138. }
  139. @include keyframes( bounce-left ) {
  140. 0%,
  141. 100% {
  142. @include transform( translateX, 0 );
  143. }
  144. 33% {
  145. @include transform( translateX, -10px );
  146. }
  147. 66% {
  148. @include transform( translateX, 3px );
  149. }
  150. }
  151. @include keyframes( bounce-right ) {
  152. 0%,
  153. 100% {
  154. @include transform( translateX, 1 );
  155. }
  156. 33% {
  157. @include transform( translateX, 10px );
  158. }
  159. 66% {
  160. @include transform( translateX, -3px );
  161. }
  162. }
  163. @include keyframes( bounce-reveal-large ) {
  164. 0%,
  165. 100% {
  166. @include transform( scale, 1 );
  167. }
  168. 33% {
  169. @include transform( scale, 1.25 );
  170. }
  171. 66% {
  172. @include transform( scale, 0.85 );
  173. }
  174. }
  175. @include keyframes( bounce-zoom ) {
  176. 0% {
  177. @include transform( scale, 1 );
  178. }
  179. 25% {
  180. @include transform( scale, 1.1 );
  181. }
  182. 75% {
  183. @include transform( scale, 0.9 );
  184. }
  185. 100% {
  186. @include transform( scale, 1.125 );
  187. }
  188. }
  189. // @-webkit-keyframes 'bounce-reveal' {
  190. // 0% { -webkit-transform: scale(0.3); }
  191. // 33% { -webkit-transform: scale(1.1); }
  192. // 66% { -webkit-transform: scale(0.9); }
  193. // 100% { -webkit-transform: scale(1); }
  194. // }
  195. // -webkit-animation: bounce-reveal 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  196. // .tag-list-wrap {
  197. //
  198. // margin-left:-999em;
  199. // -webkit-transform-origin: top left;
  200. // cursor: pointer;
  201. // position: absolute;
  202. // top: 0;
  203. //
  204. // &:hover .tag-list-wrap {
  205. //
  206. // .tags();
  207. // background: rgb(23, 23, 23);
  208. // padding: @gutter;
  209. // z-index: 20;
  210. // display: table;
  211. // word-spacing: normal;
  212. // position: absolute;
  213. // top: 0;
  214. // margin-left: 0;
  215. // -webkit-animation: bounce-reveal 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  216. // }
  217. // }