Skip to content

Instantly share code, notes, and snippets.

@antronic
Last active June 25, 2022 01:02
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 antronic/c6447c350103a16f6a06ce35b71fadf3 to your computer and use it in GitHub Desktop.
Save antronic/c6447c350103a16f6a06ce35b71fadf3 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Progress time</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
}
#wrapper {
width: 100%;
height: 5px;
background: #111;
}
#progress {
width: 0%;
height: 100%;
background: #fafafa;
transition: all 1s linear;
}
#num {
}
</style>
</head>
<body>
<div id="wrapper">
<div id="progress"></div>
</div>
<p id="num">loading...</p>
<script>
var startTime = 1656124200000
var endTime = 1656127800000
var start = new Date(startTime).getTime() // Mon Mar 21 2022 20:00:00 GMT+0700 (Indochina Time)
var target = new Date(endTime).getTime() // Mon Mar 21 2022 22:00:00 GMT+0700 (Indochina Time)
setInterval(function() {
var now = Date.now()
var diff = ((target - now) / (target - start)) * 100
var progressEl = document.querySelector('#progress')
var numEl = document.querySelector('#num')
progressEl.style.width = (100 - diff) + '%'
numEl.innerText = Number(100 - diff).toFixed(2) + '%'
}, 1000)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment