From a1e5bfd74dc641a9e71af0b16b2c46d08b55b9bd Mon Sep 17 00:00:00 2001 From: Cat Tom Date: Wed, 26 Mar 2025 12:44:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=20App.vue=20=E5=92=8C=20Parti?= =?UTF-8?q?cleBackground=20=E7=BB=84=E4=BB=B6=E4=B8=AD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E6=8E=A7=E5=88=B6=E5=92=8C=E6=80=A7=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=A1=B5=E9=9D=A2=E5=8F=AF=E8=A7=81?= =?UTF-8?q?=E6=80=A7=E5=A4=84=E7=90=86=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=8A=A8?= =?UTF-8?q?=E7=94=BB=E5=9C=A8=E9=A1=B5=E9=9D=A2=E9=9A=90=E8=97=8F=E6=97=B6?= =?UTF-8?q?=E6=9A=82=E5=81=9C=EF=BC=8C=E6=8F=90=E5=8D=87=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BD=93=E9=AA=8C=E5=92=8C=E8=B5=84=E6=BA=90=E5=88=A9=E7=94=A8?= =?UTF-8?q?=E6=95=88=E7=8E=87=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 82 +++++++++++++-------------- src/components/ParticleBackground.vue | 36 ++++++++++-- 2 files changed, 71 insertions(+), 47 deletions(-) diff --git a/src/App.vue b/src/App.vue index 0ed5b06..87cb395 100644 --- a/src/App.vue +++ b/src/App.vue @@ -77,37 +77,37 @@ import WechatModal from './components/WechatModal.vue' const showWechatModal = ref(false) -// 优化动画性能 +// 优化动画控制 +const handleVisibilityChange = () => { + const elements = document.querySelectorAll('.floating-element, .floating-bubble, .floating-flower, .floating-cloud') + const isHidden = document.hidden + + elements.forEach(el => { + if (isHidden) { + el.classList.add('animation-paused') + } else { + el.classList.remove('animation-paused') + } + }) +} + +// 优化初始化 onMounted(() => { const elements = document.querySelectorAll('.floating-element, .floating-bubble, .floating-flower, .floating-cloud') elements.forEach(el => { el.style.left = `${Math.random() * 100}vw` el.style.top = `${Math.random() * 100}vh` - // 添加硬件加速 el.style.transform = 'translateZ(0)' el.style.willChange = 'transform' + el.style.animationPlayState = 'running' }) -}) - -// 添加页面可见性检测 -onMounted(() => { + document.addEventListener('visibilitychange', handleVisibilityChange) }) onUnmounted(() => { document.removeEventListener('visibilitychange', handleVisibilityChange) }) - -const handleVisibilityChange = () => { - const elements = document.querySelectorAll('.floating-element, .floating-bubble, .floating-flower, .floating-cloud') - elements.forEach(el => { - if (document.hidden) { - el.style.animationPlayState = 'paused' - } else { - el.style.animationPlayState = 'running' - } - }) -}