Skip to content

Instantly share code, notes, and snippets.

@Pushplaybang
Forked from davej/transitionToPromise.js
Last active August 21, 2018 18:16
Show Gist options
  • Save Pushplaybang/6b625dd6909ad9f828af70252d956acd to your computer and use it in GitHub Desktop.
Save Pushplaybang/6b625dd6909ad9f828af70252d956acd to your computer and use it in GitHub Desktop.
Do a CSS transition and resolve promise when complete
const transitionToPromise = (selector, property, value) =>
new Promise(resolve => {
const el = docxument.querySelector(selector);
el.style[property] = value;
const transitionEnded = e => {
if (e.propertyName !== property) {
return;
}
el.removeEventListener('transitionend', transitionEnded);
resolve();
}
el.addEventListener('transitionend', transitionEnded);
});
/*
// Usage
transitionToPromise('.mainNav', 'opacity', '1')
.then(() => alert('Transition done'));
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment