From be284db25c713edf8d6b1c4d22b953f4d371aa39 Mon Sep 17 00:00:00 2001 From: Alberto Moretti Date: Thu, 2 Jul 2026 13:49:44 +0200 Subject: [PATCH] fix shake --- app.js | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index 8160799..dcb864b 100644 --- a/app.js +++ b/app.js @@ -361,14 +361,7 @@ const stopTicks = () => (ticking = false); // ZOOM sulla macchina + shake mentre gira - const slot = $(".slot"); - slot.classList.add("zoom"); - const shakeTimer = setTimeout(() => slot.classList.add("shake"), 460); // dopo lo zoom-in - const endZoom = () => { - clearTimeout(shakeTimer); - slot.classList.remove("shake"); // torna a scale(1.14) senza tremolio - requestAnimationFrame(() => slot.classList.remove("zoom")); // poi zoom-out fluido - }; + zoomMachineIn(); const stopRiser = Audio.riser(wantTease ? 4.6 : 4.2); startTicks(); @@ -419,7 +412,38 @@ await sleep(260); } stopRiser(); - endZoom(); // fine scroll: la macchina torna allo stato normale + // fine scroll: ferma il tremolio ma resta zoomata (il ritorno avviene + // dopo la vittoria, con una mini-animazione a molla — vedi zoomMachineOut) + zoomMachineSteady(); + } + + /* ---------- Zoom macchina ---------- */ + let _shakeTimer = null; + function zoomMachineIn() { + const slot = $(".slot"); + slot.getAnimations().forEach((a) => a.cancel()); // pulisce un eventuale ritorno in corso + slot.classList.add("zoom"); + clearTimeout(_shakeTimer); + _shakeTimer = setTimeout(() => slot.classList.add("shake"), 460); // shake dopo lo zoom-in + } + function zoomMachineSteady() { + clearTimeout(_shakeTimer); + $(".slot").classList.remove("shake"); // resta zoomata, ma ferma + } + function zoomMachineOut() { + const slot = $(".slot"); + clearTimeout(_shakeTimer); + slot.classList.remove("shake"); + slot.classList.remove("zoom"); + // mini-animazione a molla per tornare al posto (leggero rimbalzo sotto l'1) + slot.animate( + [ + { transform: "scale(1.14)" }, + { transform: "scale(0.985)" }, + { transform: "scale(1)" }, + ], + { duration: 620, easing: "cubic-bezier(0.34, 1.56, 0.64, 1)" } + ); } /* ---------- Stato di gioco ---------- */ @@ -666,6 +690,9 @@ } Audio.coin(); + // la macchina resta zoomata per godersi la vittoria, poi torna al posto + setTimeout(zoomMachineOut, isJackpot ? 1200 : 800); + cursor++; setProgress(); renderLeaderboard();