Skip to content

Instantly share code, notes, and snippets.

@adlerdias
Created January 28, 2022 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adlerdias/9bd3065e706fc5a8a5387c048af099e6 to your computer and use it in GitHub Desktop.
Save adlerdias/9bd3065e706fc5a8a5387c048af099e6 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.red {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<div id="countdown"></div>
<br >
<br >
<br >
<div id="number"></div>
<script type="text/javascript">
var loadTimer = new Promise(function(resolve, reject) {
var timeleft = 2.3;
var downloadTimer = setInterval(function(){
if(timeleft <= 0) {
clearInterval(downloadTimer);
document.getElementById("countdown").innerHTML = "Finished";
resolve("Stuff worked!");
} else {
document.getElementById("countdown").innerHTML = "Começando em " + parseFloat(timeleft).toFixed(2) + " segundos";
}
timeleft = parseFloat(timeleft - 0.10).toFixed(2);
}, 100);
});
function goToNumber(target) {
var initial = 1.00;
var progress = setInterval(function(){
if(parseFloat(initial) >= parseFloat(target)) {
clearInterval(progress);
document.getElementById("number").classList.toggle('red');
} else {
document.getElementById("number").innerHTML = parseFloat(initial).toFixed(2) + "x";
}
initial = parseFloat(initial + 0.01);
}, 10);
}
loadTimer.then(function(result) {
var target = Math.floor(Math.random() * (1000 - 100) + 100) / 100;
goToNumber(target);
}, function(err) {
console.log(err);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment