优化聊天室特效加载与移动端性能
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user