Created
July 11, 2017 13:52
-
-
Save GertjanBrouwer/ef8999cc0295ce3bf7b4ba84a5e44cc7 to your computer and use it in GitHub Desktop.
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
<html> | |
<head></head> | |
<body> | |
<p id="timer"> | |
</p> | |
<style> | |
#timer{ | |
font-size: 60px; | |
} | |
</style> | |
<script | |
src="https://code.jquery.com/jquery-3.2.1.js" | |
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" | |
crossorigin="anonymous"> | |
</script> | |
<script> | |
$(document).ready(function() { | |
var endTime = getDate(getMinutesUntilNextHour()); | |
var x = setInterval(function() { | |
var now = new Date().getTime(); | |
var distance = endTime - now; | |
var days = Math.floor(distance / (1000 * 60 * 60 * 24)); | |
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); | |
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); | |
var seconds = Math.floor((distance % (1000 * 60)) / 1000); | |
document.getElementById("timer").innerHTML = "Nog " + days + " dagen " + hours + " uur " | |
+ minutes + " minuten en " + seconds + " seconden "; | |
if (distance < 0) { | |
clearInterval(x); | |
document.getElementById("timer").innerHTML = "Nieuwe kortingscode toegevoegd, herlaad de pagina!"; | |
} | |
}, 1000); | |
}); | |
function getMinutesUntilNextHour() { | |
return 60 - new Date().getMinutes(); | |
} | |
function getDate(minutes) { | |
var ret = new Date(); | |
return ret.setTime(ret.getTime() + minutes*60000); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment