Last active
November 23, 2016 00:12
-
-
Save piotrwitek/8db7532cd9e979c4b534e81caf0e4092 to your computer and use it in GitHub Desktop.
Element animations library for React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// available animations | |
export const Animations = { | |
WIGGLE: 'u-anim-wiggle', | |
}; | |
const ANIMATION_END = 'animationend'; | |
// HOF for callbacks | |
export const animateWith = (animation: string) => | |
(ev: any) => { | |
const {currentTarget} = ev; | |
currentTarget.addEventListener(ANIMATION_END, function handler() { | |
currentTarget.classList.remove(animation); | |
currentTarget.removeEventListener(ANIMATION_END, handler); | |
}); | |
currentTarget.classList.add(animation); | |
}; | |
/* | |
CSS | |
// wiggle animation | |
.u-anim-wiggle { | |
animation: u-anim-wiggle 0.1s cubic-bezier(0.4, 1, 0.75, 0.9) 3; | |
} | |
@keyframes u-anim-wiggle { | |
0% { | |
transform: rotate(0); | |
} | |
25% { | |
transform: rotate(-5deg); | |
} | |
75% { | |
transform: rotate(5deg); | |
} | |
100% { | |
transform: rotate(0); | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: