UNPKG

vivo-ui

Version:

vivo ui component lib for vue

35 lines (28 loc) 786 B
import { raf, caf, afInterval } from '../prefix/index'; import Tween from '../tween/index'; function index (from, to, callback) { var duration = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 300; var easing = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'Linear'; var id = void 0; var time = 0; var next = function next() { 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: function pause() { caf(id); }, play: next }; } export default index;