Skip to content

Commit

Permalink
fix: rotated
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokuyow committed Nov 28, 2023
1 parent bdb0457 commit dd215a0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,20 +393,29 @@ async function updateElementsBasedOnTimestamp() {
let svg = updatePricesElement.querySelector('svg');
if (svg && !svg.classList.contains('rotated')) {
svg.classList.add('rotated');
svg.addEventListener('animationend', function () {
svg.classList.remove('rotated');
}, { once: true });
}

// データを取得
// アニメーション開始時刻を記録
const animationStartTime = Date.now();

// データを取得し計算
await fetchDataFromCoinGecko();
const updatedDiffTime = Math.floor(Date.now() / 1000) - lastUpdatedTimestamp;

// 現在の入力数値を元に再計算
if (lastUpdatedField) {
calculateValues(lastUpdatedField);
}

// 最低アニメーション持続時間を保証
const animationDuration = Date.now() - animationStartTime;
if (animationDuration < 800) {
await new Promise(resolve => setTimeout(resolve, 800 - animationDuration));
}

// アニメーションを終了
if (svg) {
svg.classList.remove('rotated');
}

// 要素のクラスを更新
updateElementClass(updatePricesElement, updatedDiffTime >= 610);
updateElementClass(lastUpdatedElement, updatedDiffTime >= 610);
Expand Down

0 comments on commit dd215a0

Please sign in to comment.