2.0.1 • Published 5 years ago

callbag-ms-elapsed v2.0.1

Weekly downloads
3,491
License
MIT
Repository
github
Last release
5 years ago

callbag-ms-elapsed

Callbag listenable source which emits milliseconds elapsed since the subscription (using requestAnimationFrame) - useful for animations.

Example

import msElapsed from 'callbag-ms-elapsed'
import forEach from 'callbag-for-each'
import map from 'callbag-map'
import pipe from 'callbag-pipe'
import takeWhile from 'callbag-take-while'

const duration = ms =>
  pipe(
    msElapsed,
    map(elapsed => elapsed / ms),
    takeWhile(factor => factor <= 1),
  )

const distance = d => t => t * d

const moveBall = (ball, easing) => {
  pipe(
    duration(1000),
    map(easing),
    map(distance(400)),
    forEach(y => {
      ball.style.transform = `translate3d(0, ${y}px, 0)`
    }),
  )
}

const easeOut = p => 1 - (1 - p) * (1 - p)

moveBall(document.getElementById('ball'), easeOut)
2.0.1

5 years ago

2.0.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago