Last active
August 30, 2018 07:37
-
-
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)
This file contains 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
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