ant-design-vue/components/_util/requestAnimationTimeout.js

23 lines
501 B
JavaScript
Raw Normal View History

2018-02-04 03:08:04 +00:00
import getRequestAnimationFrame, { cancelRequestAnimationFrame as caf } from './getRequestAnimationFrame'
const raf = getRequestAnimationFrame()
export const cancelAnimationTimeout = (frame) => caf(frame.id)
export const requestAnimationTimeout = (callback, delay) => {
const start = Date.now()
function timeout () {
if (Date.now() - start >= delay) {
callback.call()
} else {
frame.id = raf(timeout)
}
}
const frame = {
id: raf(timeout),
}
return frame
}