0.3.0 • Published 5 years ago

tail-end v0.3.0

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

tail-end

tail-end on NPM tail-end Downloads on NPM Standard JavaScript Style

Promise-wrapped CSS animations and transitions (async/await friendly).

Install

$ npm i tail-end --save

API

The following functions are exported:

  • animationEnd(node[, function])
  • transitionEnd(node[, function])

Both exports add a Promise-wrapped event handler to the node. The Promise removes the event listener and resolves itself when the event is triggered.

import { animationEnd } from 'tail-end'

// bind the event, then trigger it
animationEnd(node)
  .then(() => console.log('Transition ended.'))
  .catch(error => console.log('Invalid node passed in: ', error))

node.classList.add('will-animate')

For usage with async/await you can pass in a function as the second parameter. The function will be called in an animation frame after the event listener is bound, and passed the node.

import { transitionEnd } from 'tail-end'

// define a sequence of animations/transitions with async/await
const sequence = async () => {
  await transitionEnd(node, node => node.style.transform = 'translate3d(100px, 0, 0)')
  await transitionEnd(node, node => node.style.transform = 'translate3d(0, 0, 0)')
  await transitionEnd(node, node => node.style.transform = 'translate3d(-100px, 0, 0)')
}

// run the sequence
sequence().then(() => console.log('Sequence completed.'))

License

MIT. © 2018 Michael Cavalea

0.3.0

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

7 years ago

0.0.1

7 years ago