Simple countdown using Greensock. You could add an "onComplete" to the Tweenlite to trigger an event when the countdown ends.
Last active
September 30, 2015 03:14
-
-
Save chowey/795c3aaafeddbefd8680 to your computer and use it in GitHub Desktop.
Movie Countdown with Greensock
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
body { | |
background: #000; | |
} | |
.dial-wrapper { | |
font-size: 72px; | |
margin: auto; | |
position: relative; | |
width: 2em; | |
height: 2em; | |
border-radius: 2em; | |
background: rgba(255,255,255,0.1); | |
} | |
.dial-counter { | |
display: block; | |
width: 2em; | |
line-height: 2em; | |
text-align: center; | |
color: rgba(255,255,255,0.5); | |
} | |
.dial-wrapper:after { | |
content: ''; | |
position: absolute; | |
display: block; | |
top: -4px; | |
right: -4px; | |
bottom: -4px; | |
left: -4px; | |
border-radius: 2em; | |
border: 2px solid rgba(255,255,255,0.2); | |
} | |
.dial-container { | |
position: absolute; | |
top: 0; | |
bottom: 0; | |
overflow: hidden; | |
width: 50%; | |
} | |
.dial-wedge { | |
background: rgba(255,255,255,0.2); | |
height: 100%; | |
width: 100%; | |
} | |
.dial-container1 { | |
left: 50%; | |
} | |
.dial-container1 .dial-wedge { | |
border-radius: 0 1em 1em 0; | |
} | |
.dial-container2 { | |
left: 0; | |
} | |
.dial-container2 .dial-wedge { | |
border-radius: 1em 0 0 1em; | |
} | |
.dial-hand { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 50%; | |
height: 50%; | |
border-right: 3px solid rgba(255,255,255,0.5); | |
} | |
</style> | |
</head> | |
<body> | |
<div class="dial-wrapper"> | |
<div class="dial-counter">5</div> | |
<div class="dial-container dial-container1"> | |
<div class="dial-wedge"></div> | |
</div> | |
<div class="dial-container dial-container2"> | |
<div class="dial-wedge"></div> | |
</div> | |
<div class="dial-hand"></div> | |
</div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/plugins/CSSPlugin.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/TweenLite.min.js"></script> | |
<script> | |
(function (control) { | |
var counter = document.querySelector('.dial-counter'), | |
hand = document.querySelector('.dial-hand'), | |
container1 = document.querySelector('.dial-container1 .dial-wedge'), | |
container2 = document.querySelector('.dial-container2 .dial-wedge'), | |
count = ~~counter.textContent; | |
TweenLite.set(hand, { transformOrigin: '100% 100%' }); | |
TweenLite.set(container1, { transformOrigin: '0 50%' }); | |
TweenLite.set(container2, { transformOrigin: '100% 50%' }); | |
TweenLite.to(control, count, { | |
t: count, | |
onUpdate: function () { | |
var t = control.t; | |
TweenLite.set(hand, { rotation: t*360 }); | |
TweenLite.set(container1, { rotation: (t % 1 > 0.5) ? 180 : t*360 }); | |
TweenLite.set(container2, { rotation: (t % 1 < 0.5) ? 0 : t*360 + 180 }); | |
counter.textContent = Math.ceil(count - t); | |
}, | |
ease:Linear.easeNone | |
}); | |
})({t: 0}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment