aos to cdn

This commit is contained in:
tangly1024.com
2024-04-10 16:47:57 +08:00
parent c43943b0bb
commit b2b64c8f76
4 changed files with 23 additions and 26 deletions

View File

@@ -1,12 +1,30 @@
import { isBrowser } from '@/lib/utils'
import AOS from 'aos'
import { loadExternalResource } from '@/lib/utils'
import { useEffect } from 'react'
// import AOS from 'aos'
/**
* 加载滚动动画
* 改从外部CDN读取
* https://michalsnik.github.io/aos/
*/
export default function AOSAnimation() {
if (isBrowser) {
AOS.init()
const initAOS = async () => {
Promise.all([
loadExternalResource(
'https://cdn.bootcdn.net/ajax/libs/aos/2.3.4/aos.js',
'js'
),
loadExternalResource(
'https://cdn.bootcdn.net/ajax/libs/aos/2.3.4/aos.css',
'css'
)
]).then(() => {
if (window.AOS) {
window.AOS.init()
}
})
}
useEffect(() => {
initAOS()
}, [])
}