Created
June 21, 2013 09:32
-
-
Save mrakowski0/5830063 to your computer and use it in GitHub Desktop.
Simple countdown timer with zero hour listener.
This file contains hidden or 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
| %body | |
| %article | |
| .countdown | |
| %span Time left: | |
| .days{"data-unit" => "day"} | |
| .hours{"data-unit" => "hrs"} | |
| .minutes{"data-unit" => "min"} | |
| .seconds{"data-unit" => "sec"} |
This file contains hidden or 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
| 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); |
This file contains hidden or 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
| .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