A Pen by Joshua Pike on CodePen.
Created
October 6, 2017 07:18
-
-
Save jpike88/e6db33fb4beed786e2c5d8ff2e6a0efa to your computer and use it in GitHub Desktop.
Countdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="timer" class="centered"> | |
<div id="hours"></div> | |
<div id="minutes"></div> | |
<div id="seconds"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date.prototype.addHours = function(h) { | |
this.setTime(this.getTime() + (h*60*60*1000)); | |
return this; | |
} | |
var hours = prompt("Please enter the hours", "240"); | |
//var hours = 210; | |
var nowTemp = new Date(); | |
var endTime = nowTemp.setHours(nowTemp.getHours()+parseInt(hours)) / 1000; | |
function makeTimer() { | |
var nowDate = new Date(); | |
var now = nowDate.getTime() / 1000; | |
var timeLeft = endTime - now; | |
var days = Math.floor(timeLeft / 86400); | |
var hours = Math.floor((timeLeft) / 3600); | |
var realHours = Math.floor((timeLeft - (days * 86400)) / 3600); | |
var minutes = Math.floor((timeLeft - (days * 86400) - (realHours * 3600 )) / 60); | |
var seconds = Math.floor((timeLeft - (days * 86400) - (realHours * 3600) - (minutes * 60))); | |
if (hours < "10") { hours = "0" + hours; } | |
if (minutes < "10") { minutes = "0" + minutes; } | |
if (seconds < "10") { seconds = "0" + seconds; } | |
$("#days").html(days); | |
$("#hours").html(hours + " : "); | |
$("#minutes").html(minutes + " : "); | |
$("#seconds").html(seconds); | |
} | |
setInterval(function() { makeTimer(); }, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import url(https://fonts.googleapis.com/css?family=Covered+By+Your+Grace); | |
.centered { | |
width:100%; | |
position: fixed; | |
top: 50%; | |
left: 50%; | |
/* bring your own prefixes */ | |
transform: translate(-50%, -50%); | |
} | |
#days { | |
font-size: 150px; | |
color: #db4844; | |
} | |
#hours { | |
font-size: 150px; | |
color: #fff; | |
} | |
#minutes { | |
font-size: 150px; | |
color: #fff; | |
} | |
#seconds { | |
font-size: 150px; | |
color: #fff; | |
} | |
div { | |
display: inline-block; | |
line-height: 1; | |
padding: 20px; | |
font-size: 40px; | |
} | |
span { | |
display: block; | |
font-size: 20px; | |
color: white; | |
} | |
body { | |
text-align: center; | |
/*font-family: 'Covered By Your Grace', cursive; | |
*/ | |
color: white; | |
background: #222; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment