https://github.com/callmecavs/tail-end
Promise-wrapped CSS animations and transitions (async/await friendly).
https://github.com/callmecavs/tail-end
animationend async await css promise transitionend
Last synced: about 1 year ago
JSON representation
Promise-wrapped CSS animations and transitions (async/await friendly).
- Host: GitHub
- URL: https://github.com/callmecavs/tail-end
- Owner: callmecavs
- Created: 2017-03-16T01:26:03.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-12-28T23:13:52.000Z (over 7 years ago)
- Last Synced: 2025-03-29T07:22:46.435Z (over 1 year ago)
- Topics: animationend, async, await, css, promise, transitionend
- Language: HTML
- Homepage:
- Size: 59.6 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tail-end
[](https://www.npmjs.com/package/tail-end) [](https://www.npmjs.com/package/tail-end) [](http://standardjs.com/)
Promise-wrapped CSS animations and transitions (`async`/`await` friendly).
## Install
```sh
$ 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.
```javascript
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](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) after the event listener is bound, and passed the `node`.
```javascript
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](https://opensource.org/licenses/MIT). © 2018 Michael Cavalea