<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Balence Incrementer</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="lib/style.css" />
</head>
<body>
<app>
<header>
<section>
<span>9:41</span><span></span><span>█ █ █</span>
</section>
<section>
<span></span><span class="logo">LOGO</span><span></span>
</section>
</header>
<main>
<ul class="tabs">
<li>Checking</li>
<li>Savings</li>
<li>Credit</li>
</ul>
<h1>Avaliable Balence</h1>
<section>
<display class="balance">
<currency>$</currency>
<dollars id="dollars">---</dollars>
<cents id="cents">--</cents>
</display>
</section>
<section>
<p>
<input id="target" type="number" value="2750.91" />
<button onclick="AnimateBalance.redo()">Redo</button>
</p>
<p>
<label
><input type="checkbox" id="apiDelay" /> Simulate API delay</label
>
</p>
<p>
<small>Seconds ellapsed: <span id="secondsDisplay">00</span></small>
</p>
</section>
</main>
</app>
<script src="lib/script.js"></script>
</body>
</html>
/* Add your styles here */
*,
::after,
::before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
BODY,
HTML {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
BODY {
font-family: "Poppins", sans-serif;
font-size: 16px;
text-align: center;
line-height: 1;
font-weight: 400;
font-style: normal;
}
CURRENCY,
CENTS {
font-size: 36px;
}
DOLLARS {
font-size: 80px;
}
DISPLAY {
display: inline-grid;
grid-template-columns: auto auto auto;
}
DISPLAY > * {
padding: 0;
font-weight: 600;
}
CURRENCy {
align-self: center;
}
DOLLARS {
align-self: end;
}
CENTS {
align-self: start;
}
SECTION {
display: block;
margin-bottom: 20vh;
}
APP {
display: block;
padding: 0;
width: 375px;
margin: 1em auto;
border: 1px solid;
border-radius: 16px;
}
MAIN,
H1 {
max-width: 100%;
padding: 0;
margin: 0;
}
MAIN {
padding: 1em;
margin: 1em auto;
}
INPUT,
BUTTON {
font-size: 1 rem;
padding: 0.5em 2em;
}
INPUT {
display: inline-block;
width: auto;
text-align: right;
}
HEADER {
padding: 0.25em 1em;
}
HEADER SECTION,
FOOTER SECTION {
display: flex;
margin: 0;
}
HEADER SECTION SPAN {
flex: 1 1 33%;
font-size: 12px;
}
HEADER SECTION SPAN:first-child {
text-align: left;
}
HEADER SECTION SPAN:last-child {
text-align: right;
}
HEADER .logo,
FOOTER .menu {
font-size: 24px;
}
HEADER {
border-bottom: 1px solid;
}
UL {
margin: 0 0 32px;
padding: 0;
display: flex;
border-bottom: 1px solid lightgray;
justify-content: center;
align-items: center;
}
UL LI {
flex: 1 1 33%;
display: flex;
justify-content: center;
align-items: center;
padding: 8px;
}
UL LI:first-child {
font-weight: 600;
border-bottom: 2px solid blue;
}
H1 {
font-weight: normal;
font-size: 16px;
color: gray;
padding-bottom: 20px;
}
/***/
BODY {
background-color: lightgrey;
color: #262626;
}
HEADER {
border: none;
font-size: 24px;
font-weight: 600;
line-height: 1;
color: black;
padding: 16px 32px 4px;
box-shadow: 0 4px 8px -2px rgba(0, 0, 0, 0.15);
background-color: white;
border-radius: 16px 16px 0 0;
}
HEADER > *:first-child {
height: 24px;
}
HEADER .logo {
font-weight: normal;
color: blue;
}
APP {
background-color: white;
border: none;
}
// JS is messy; proof of concept
const AnimateBalance = {
dollarsEl: document.getElementById('dollars'),
centsEl: document.getElementById('cents'),
begin: 0.0,
current: 0.0,
formatDollars(value) {
return value.toLocaleString('en-US', {
minimumFractionDigits: 0,
maximumFractionDigits: 0,
});
},
formatCents(value) {
let formattedValue = value.toLocaleString('en-US', {
minimumFractionDigits: 0,
maximumFractionDigits: 0,
});
return formattedValue.padStart(2, '0');
},
async redo() {
let apiDelay = document.getElementById('apiDelay');
AnimateBalance.dollarsEl.innerText = '---';
AnimateBalance.centsEl.innerText = '--';
AnimateBalance.count = 0;
AnimateBalance.countDisplay.innerText = 0;
AnimateBalance.toggleCount(1);
if (apiDelay.checked) {
await AnimateBalance.sleep(2000);
}
(AnimateBalance.innerText = 0), (AnimateBalance.dollarsEl.innerText = 0);
AnimateBalance.centsEl.innerText = 00;
AnimateBalance.init();
},
sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
},
async init() {
let target = parseFloat(document.getElementById('target').value);
let cents = function () {
let temp = target + '';
let amount = temp.split('.');
if (amount[1]) {
return amount[1];
} else {
return 0;
}
};
let sleepIncrement = 1;
AnimateBalance.toggleCount(1);
// Loop 1: For Cents Increment
const centsLoop = new Promise(async (resolve) => {
let incrementCentsValue = 1;
for (let j = 0; j <= cents(); j = j + incrementCentsValue) {
AnimateBalance.centsEl.innerText = AnimateBalance.formatCents(j);
await AnimateBalance.sleep(sleepIncrement);
}
resolve(); // Mark the cents loop as completed
});
// Loop 2: For Dollar Increment
const dollarLoop = new Promise(async (resolve) => {
let incrementDollarValue = 10;
for (let i = 0; i <= target; i = i + incrementDollarValue) {
AnimateBalance.dollarsEl.innerText = AnimateBalance.formatDollars(i);
await AnimateBalance.sleep(sleepIncrement);
// Uneven amounts look more like a realistic out up
if (target - i >= 5000) {
// incrementDollarValue = 321;
incrementDollarValue = 300;
}
if (target - i < 5000 && target - i > 2001) {
// incrementDollarValue = 101;
incrementDollarValue = 100;
}
if (target - i < 2000 && target - i > 50) {
// incrementDollarValue = 9;
incrementDollarValue = 10;
}
if (target - i <= 50) {
incrementDollarValue = 1;
}
}
resolve(); // Mark the dollar loop as completed
});
// Wait for both loops to complete simultaneously
await Promise.all([centsLoop, dollarLoop]);
AnimateBalance.toggleCount(0);
},
count: 0,
intervalId: null,
countDisplay: document.getElementById('secondsDisplay'),
toggleCount(startStop) {
// Start counting when startStop is 1
if (startStop === 1 && AnimateBalance.intervalId === null) {
AnimateBalance.intervalId = setInterval(() => {
AnimateBalance.count++;
AnimateBalance.countDisplay.innerText = AnimateBalance.count;
}, 1000);
}
// Stop counting when startStop is 0
else if (startStop === 0 && AnimateBalance.intervalId !== null) {
clearInterval(AnimateBalance.intervalId);
AnimateBalance.intervalId = null;
}
},
};
AnimateBalance.init();
.poppins-regular {
font-family: "Poppins", sans-serif;
font-weight: 400;
font-style: normal;
}
.poppins-semibold {
font-family: "Poppins", sans-serif;
font-weight: 600;
font-style: normal;
}
.poppins-bold {
font-family: "Poppins", sans-serif;
font-weight: 700;
font-style: normal;
}
.poppins-regular-italic {
font-family: "Poppins", sans-serif;
font-weight: 400;
font-style: italic;
}
.poppins-semibold-italic {
font-family: "Poppins", sans-serif;
font-weight: 600;
font-style: italic;
}
.poppins-bold-italic {
font-family: "Poppins", sans-serif;
font-weight: 700;
font-style: italic;
}
Animate Balance
-- Increment from zero to a balance by a high value increments until close 10 from value then increment by 1.
-- Output dollars and cents independently.
-- Increment cents by 1
-- Increment dollars based on the value
As the incrementing value approaches the total...
Calculating the Dollar increment value:
Dollar Increment Value (v)
Count (i) starts at 0 and increments towards TARGET
Difference (d) = TARGET - i;
When d > 2000, v = 100
When d > 10, v = 10
When d < 10, v = 1