延迟加载挂件

This commit is contained in:
tangly1024
2022-05-13 15:31:41 +08:00
parent ea148835f6
commit d9d7839e7d

View File

@@ -17,7 +17,10 @@ export default function Live2D() {
}
useEffect(() => {
initLive2D()
window.addEventListener('scroll', initLive2D)
return () => {
window.removeEventListener('scroll', initLive2D)
}
}, [])
return <canvas id="live2d" className='cursor-pointer' width="280" height="250" onClick={handleClick} alt='切换主题' title='切换主题' />
@@ -27,6 +30,7 @@ export default function Live2D() {
* 加载宠物
*/
function initLive2D() {
window.removeEventListener('scroll', initLive2D)
setTimeout(() => {
// 加载 waifu.css live2d.min.js waifu-tips.js
if (screen.width >= 768) {
@@ -38,5 +42,5 @@ function initLive2D() {
loadlive2d('live2d', BLOG.WIDGET_PET_LINK)
})
}
}, 1000)
}, 300)
}