Skip to content

Instantly share code, notes, and snippets.

@Muzietto
Last active August 30, 2018 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Muzietto/1685f0306b5e62713dce0d398c9a4403 to your computer and use it in GitHub Desktop.
Save Muzietto/1685f0306b5e62713dce0d398c9a4403 to your computer and use it in GitHub Desktop.
Simple Swiping Up, compare with the White Rabbit (https://codepen.io/rachelnabors/pen/eJyWzm)
export function playSwipeInAnimation(element, height) {
const ANIMATION_DURATION = 500;
const TIMING = {
duration: ANIMATION_DURATION,
fill: 'forwards',
easing: 'cubic-bezier(0.42,0,0.58,1)',
};
const KEYFRAMES = [
{
marginBottom: `-${height}px`,
},
{
marginBottom: '0',
},
];
const effect = new window.KeyframeEffect(element, KEYFRAMES, TIMING);
const animation = new window.Animation(effect, document.timeline);
return playAnimationPromise(animation);
}
function playAnimationPromise(animation) {
return new Promise((resolve, reject) => {
window.requestAnimationFrame(genericAnimationFrameCallback(animation, resolve, reject))
});
}
function genericAnimationFrameCallback(animation, resolve, reject) {
try {
animation.onfinish = () => resolve(animation);
animation.play();
} catch (e) {
console.error(e);
reject(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment