Skip to content

Instantly share code, notes, and snippets.

@pixelthing
Last active August 29, 2015 13:57
Show Gist options
  • Save pixelthing/9782842 to your computer and use it in GitHub Desktop.
Save pixelthing/9782842 to your computer and use it in GitHub Desktop.
SASS CSS animation mixin
/* animation mixins */
@import "compass/css3/shared"
@mixin animation ($animation_name, $duration: 500ms, $fill_mode: forwards, $iteration_count: 1, $delay: 0, $direction: normal, $timing_function: ease)
+experimental(animation-name, $animation_name)
+experimental(animation-duration, $duration)
@if $fill_mode != none
+experimental(animation-fill-mode, $fill_mode)
@if $iteration_count != 1
+experimental(animation-iteration-count, $iteration_count)
@if $delay != 0
+experimental(animation-delay, $delay)
@if $direction != normal
+experimental(animation-direction, $direction)
@if $timing_function != ease
+experimental(animation-timing-function, $timing_function)
@mixin keyframe ($animation_name)
@-webkit-keyframes #{$animation_name}
@content
@-moz-keyframes #{$animation_name}
@content
@keyframes #{$animation_name}
@content
/* example animation */
@include keyframe(pointypoint)
0%
+transform(translateY(0))
50%
+transform(translateY(10px))
100%
+transform(translateY(0))
.bob:hover
@include animation(pointypoint, 500ms, forwards, infinite)
@pixelthing
Copy link
Author

A mixin to make my life easier with animations (as animations isn't in compass by default - currently)

It's built to give all the options you need, but not to spit out all rules if most of them are defaults, to reduce the size of the code.

PS - sorry Opera 12 users, but the -o-animation prefix was apparently only ever used in Opera12, so on balance I decided smaller code was a bigger concern.

@pixelthing
Copy link
Author

updated based on some ace work by @annez (as usual) https://gist.github.com/annez/9783177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment