PHP
·
发表于 5年以前
·
阅读量:8289
const fade = (el, type = 'in') {
el.style.opacity = (type === 'in' ? 0 : 1)
let last = +new Date()
const tick = () => {
const opacityValue = (type === 'in'
? (new Date() - last) / 400
: -(new Date() - last) / 400)
el.style.opacity = +el.style.opacity + opacityValue
last = +new Date()
if (type === 'in'
? (+el.style.opacity < 1)
: (+el.style.opacity > 0)) {
requestAnimationFrame(tick)
}
}
tick()
}