优化聊天室特效加载与移动端性能

This commit is contained in:
2026-04-25 03:34:19 +08:00
parent 128b52d0aa
commit e3cba255f9
6 changed files with 158 additions and 25 deletions
+5 -2
View File
@@ -92,7 +92,10 @@ const ConfettiEffect = (() => {
const w = canvas.width;
const h = canvas.height;
const DURATION = 7800;
let pieces = Array.from({ length: 90 }, () => new Piece(w, h));
const isMobile = window.matchMedia?.("(max-width: 640px)")?.matches || window.innerWidth <= 640;
const initialPieceCount = isMobile ? 56 : 90;
const spawnPieceCount = isMobile ? 6 : 10;
let pieces = Array.from({ length: initialPieceCount }, () => new Piece(w, h));
const startTime = performance.now();
let lastSpawnAt = startTime;
let animId = null;
@@ -129,7 +132,7 @@ const ConfettiEffect = (() => {
});
if (now - startTime < DURATION * 0.9 && now - lastSpawnAt >= 120) {
pieces.push(...Array.from({ length: 10 }, () => new Piece(w, h)));
pieces.push(...Array.from({ length: spawnPieceCount }, () => new Piece(w, h)));
lastSpawnAt = now;
}