ntdservices commited on
Commit
c46d31f
·
verified ·
1 Parent(s): 00aa4f4

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +19 -11
templates/index.html CHANGED
@@ -34,6 +34,23 @@
34
  let startingDebt = 0;
35
  let ratePerSecond = 0;
36
  let startTime = Date.now();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  fetch('/api/debt')
39
  .then(res => res.json())
@@ -41,22 +58,13 @@
41
  startingDebt = data.startingDebt;
42
  ratePerSecond = data.ratePerSecond;
43
  startTime = Date.now();
44
- updateDebtDisplay();
45
- setInterval(updateDebtDisplay, 100);
46
  })
47
  .catch(err => {
48
  document.getElementById('debt').textContent = 'Error loading data';
49
  console.error(err);
50
  });
51
-
52
- function updateDebtDisplay() {
53
- let elapsed = (Date.now() - startTime) / 1000;
54
- let currentDebt = startingDebt + (ratePerSecond * elapsed);
55
- document.getElementById('debt').textContent = '$' + currentDebt.toLocaleString(undefined, {
56
- minimumFractionDigits: 2,
57
- maximumFractionDigits: 2
58
- });
59
- }
60
  </script>
61
  </body>
62
  </html>
 
34
  let startingDebt = 0;
35
  let ratePerSecond = 0;
36
  let startTime = Date.now();
37
+ let currentDisplayDebt = 0;
38
+
39
+ function animateDebt() {
40
+ const now = Date.now();
41
+ const elapsed = (now - startTime) / 1000;
42
+ const targetDebt = startingDebt + (ratePerSecond * elapsed);
43
+
44
+ // Easing toward target
45
+ currentDisplayDebt += (targetDebt - currentDisplayDebt) * 0.05;
46
+
47
+ document.getElementById('debt').textContent = '$' + currentDisplayDebt.toLocaleString(undefined, {
48
+ minimumFractionDigits: 2,
49
+ maximumFractionDigits: 2
50
+ });
51
+
52
+ requestAnimationFrame(animateDebt);
53
+ }
54
 
55
  fetch('/api/debt')
56
  .then(res => res.json())
 
58
  startingDebt = data.startingDebt;
59
  ratePerSecond = data.ratePerSecond;
60
  startTime = Date.now();
61
+ currentDisplayDebt = startingDebt;
62
+ animateDebt();
63
  })
64
  .catch(err => {
65
  document.getElementById('debt').textContent = 'Error loading data';
66
  console.error(err);
67
  });
 
 
 
 
 
 
 
 
 
68
  </script>
69
  </body>
70
  </html>