Skip to content

Instantly share code, notes, and snippets.

@mrakowski0
Created June 21, 2013 09:32
Show Gist options
  • Select an option

  • Save mrakowski0/5830063 to your computer and use it in GitHub Desktop.

Select an option

Save mrakowski0/5830063 to your computer and use it in GitHub Desktop.
Simple countdown timer with zero hour listener.
%body
%article
.countdown
%span Time left:
.days{"data-unit" => "day"}
.hours{"data-unit" => "hrs"}
.minutes{"data-unit" => "min"}
.seconds{"data-unit" => "sec"}
countdownTimer = ->
BigDay = new Date("28 Jun 2013, 16:00:00")
msPerDay = 24 * 60 * 60 * 1000
handleTimer = ->
today = new Date()
timeLeft = (BigDay.getTime() - today.getTime())
e_daysLeft = timeLeft / msPerDay
daysLeft = Math.floor(e_daysLeft)
e_hrsLeft = (e_daysLeft - daysLeft) * 24
hrsLeft = Math.floor(e_hrsLeft)
e_minsLeft = (e_hrsLeft - hrsLeft) * 60
minsLeft = Math.floor(e_minsLeft)
e_secsLeft = (e_minsLeft - minsLeft) * 60
secsLeft = Math.floor(e_secsLeft)
updateCounter = ->
if daysLeft is 0 and hrsLeft is 0 and minsLeft is 0 and secsLeft is 0
window.clearInterval(timerUpdate)
$('.countdown').addClass 'completed'
unless today > BigDay
$(".countdown .days").html daysLeft
$(".countdown .hours").html hrsLeft
$(".countdown .minutes").html minsLeft
$(".countdown .seconds").html secsLeft
else
$('.countdown').addClass 'completed'
$('.countdown > div').html '0'
updateCounter()
timerUpdate = window.setInterval(handleTimer, 1000);
.countdown {
background: rgba(0,0,0,0.2);
padding: 2px 2px 20px 2px;
&.completed {
background: rgba(111,153,22,0.2);
& > div {
background: $highlight;
}
}
& > div {
@include transition(all 0.5s ease-out);
@include background-image(linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.9)));
@include border-radius(2px);
margin: 2px;
float: left;
width: 30px;
font: 24px "Roboto", sans-serif;
padding: 8px;
position: relative;
&:after {
content: attr(data-unit);
position: absolute;
bottom: -18px;
font-size: 12px;
left: 14px;
}
}
& > span {
display: block;
}
.hours {
&:after {
left: 10px;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment