flat: 性能优化,animation 等\preload等
This commit is contained in:
30
hook/page-animation.css
Normal file
30
hook/page-animation.css
Normal file
@@ -0,0 +1,30 @@
|
||||
/* #ifdef H5 */
|
||||
uni-page {
|
||||
opacity: 1;
|
||||
will-change: opacity;
|
||||
}
|
||||
|
||||
/* --- 进场 (Enter) --- */
|
||||
uni-page.animation-enter-from {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
uni-page.animation-enter-active {
|
||||
transition: opacity 0.2s ease-out;
|
||||
}
|
||||
|
||||
/* --- 离场 (Leave) --- */
|
||||
uni-page.animation-leave-active {
|
||||
transition: opacity 0.15s ease-in;
|
||||
}
|
||||
|
||||
uni-page.animation-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* --- 稳态 --- */
|
||||
uni-page.animation-show {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* #endif */
|
||||
66
hook/usePageAnimation.js
Normal file
66
hook/usePageAnimation.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
onLaunch
|
||||
} from '@dcloudio/uni-app'
|
||||
import {
|
||||
getCurrentInstance
|
||||
} from 'vue'
|
||||
import './page-animation.css'
|
||||
|
||||
const DURATION = 130
|
||||
|
||||
export default function usePageAnimation() {
|
||||
// #ifdef H5
|
||||
const show = () => {
|
||||
const page = document.querySelector('uni-page')
|
||||
if (!page) return
|
||||
const cl = page.classList
|
||||
|
||||
cl.add('animation-enter-from')
|
||||
cl.remove('animation-leave-to', 'animation-leave-active')
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(() => {
|
||||
cl.remove('animation-enter-from')
|
||||
cl.add('animation-enter-active', 'animation-show')
|
||||
|
||||
setTimeout(() => {
|
||||
cl.remove('animation-enter-active')
|
||||
}, DURATION)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const hide = (next) => {
|
||||
const page = document.querySelector('uni-page')
|
||||
if (!page) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
const cl = page.classList
|
||||
|
||||
cl.add('animation-leave-active')
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
cl.remove('animation-show')
|
||||
cl.add('animation-leave-to')
|
||||
|
||||
setTimeout(() => {
|
||||
cl.remove('animation-leave-active', 'animation-leave-to')
|
||||
next()
|
||||
}, DURATION - 50)
|
||||
})
|
||||
}
|
||||
|
||||
onLaunch(() => {
|
||||
const instance = getCurrentInstance()
|
||||
const router = instance?.proxy?.$router
|
||||
if (router) {
|
||||
show()
|
||||
|
||||
router.beforeEach((to, from, next) => hide(next))
|
||||
|
||||
router.afterEach(() => show())
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
Reference in New Issue
Block a user