A Pen by Luke Galea on CodePen.
Last active
December 22, 2015 20:19
-
-
Save lukegalea/6525408 to your computer and use it in GitHub Desktop.
A Pen by Luke Galea.
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 class="before"> | |
<div class="daysBefore"> | |
It's | |
<span class="days"></span> | |
days before | |
</div> | |
<div class="hoursBefore"> | |
It's | |
<span class="hours"></span> | |
hours before | |
</div> | |
</div> | |
<div class="open"> | |
It's open | |
</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
$(function() { | |
var daysAway, hoursAway, launchDate, now, isLaunched; | |
launchDate = moment("09-17-2013 10:00 +5", "MM-DD-YYYY HH:mm Z"); | |
now = moment(); | |
daysAway = launchDate.diff(now, 'days'); | |
hoursAway = launchDate.diff(now, 'hours'); | |
isLaunched = now.isAfter(launchDate); | |
$('.days').text(daysAway); | |
$('.hours').text(hoursAway); | |
$('.before').toggle(!isLaunched); | |
$('.open').toggle(isLaunched); | |
$('.daysBefore').toggle(hoursAway > 24); | |
$('.hoursBefore').toggle(hoursAway <= 24); | |
}); |
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
.hidden { | |
display: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, this requires http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.1.0/moment.min.js