vivo-ui
Version:
vivo ui component lib for vue
29 lines (25 loc) • 582 B
JavaScript
import { raf, caf, afInterval } from '../prefix/index'
import Tween from '../tween/index'
export default function (from, to, callback, duration = 300, easing = 'Linear') {
let id
let time = 0
const next = function () {
if (time < duration) {
callback(easing(time, from, to - from, duration))
time++
id = raf(next)
} else {
callback(to, true)
}
}
duration = Math.floor(duration / afInterval)
easing.split('.').forEach(function (key) {
easing = Tween[key]
})
return {
pause () {
caf(id)
},
play: next
}
}