Skip to content

Instantly share code, notes, and snippets.

Created November 12, 2014 11:26
Show Gist options
  • Save anonymous/b477f37e88912c24f37d to your computer and use it in GitHub Desktop.
Save anonymous/b477f37e88912c24f37d to your computer and use it in GitHub Desktop.
A Pen by mnmly.
<div class='small'>minimal counter</div>
<div class='wrapper'>
<div id="a" />
</div>
<a href="http://mnmly.com" target="_blank">mnmly</a>
<a class='github' href="https://github.com/mnmly/minimal-counter" target="_blank">github</a>
class Counter
sequence = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0].join('\n')
constructor: (@el)->
@el.addClass('counter')
@el.html(@template)
@tensPlaceSequence = @el.find('.sequence').eq(0)
@onesPlaceSequence = @el.find('.sequence').eq(1)
template: """
<div class='digit'>
<div class='sequence'>#{sequence}</div>
</div>
<div class='digit'>
<div class='sequence'>#{sequence}</div>
</div>
"""
countUpTo: (number)->
tensPlace = Math.floor(number / 10)
onesPlace = number % 10
if tensPlace isnt 0
@tensPlaceSequence.removeClass('is-hidden')
setTimeout =>
@tensPlaceSequence.css
'-webkit-transform': "translate3d(0, #{- (9 - tensPlace) * 10}%, 0)"
,0
else
@tensPlaceSequence.addClass('is-hidden')
@onesPlaceSequence.css
'-webkit-transform': "translate3d(0, #{- (9 - onesPlace) * 10}%, 0)"
$ ->
counter = new Counter($('#a'))
setInterval =>
value = Math.round(Math.random() * 100)
counter.countUpTo( value )
, 2000
.counter {
font-size: 0;
height: 60px;
overflow: hidden;
font-family: Helvetica Neue;
font-weight: bold;
text-align: center;
}
.counter .digit {
display: inline-block;
font-size: 56px;
text-align: center;
}
.counter .sequence {
width: 0.55em;
-webkit-transform: translate3d(0, -90%, 0);
-webkit-transition: -webkit-transform 400ms cubic-bezier(0.86, 0, 0.07, 1) /* easequint*/,
width 400ms ease-in-out,
opacity 400ms ease-in-out;
}
.counter .digit:last-child .sequence{
-webkit-transition-delay: 100ms;
}
.counter .sequence.is-hidden {
width: 0.02em;
opacity: 0;
}
body{
text-align: left;
margin-top: 100px;
margin-left: 150px;
}
.small{
font-family: 'consolas', monospace;
font-size: 12px;
color: hsl(0, 0%, 30%);
text-indent: 2px;
padding-bottom: 10px;
position: relative;
margin-bottom: 30px;
border-top: 5px solid black;
width: 200px;
padding-top: 20px;
}
.small::after{
content: '';
display: block;
position: absolute;
width: 15px;
height: 1px;
background: hsl(0, 0%, 60%);
bottom: -15px;
left: 2px;
}
#a{
display: inline-block;
}
.wrapper{
color: hsl(0, 0%, 10%);
}
.wrapper::after{
content: '%';
font-size: 20px;
font-family: "Helvetica Neue";
font-weight: bold;
position: relative;
top: -5px;
display: inline-block;
}
a{
font-family: 'Helvetica Neue';
font-size: 12px;
font-weight: bold;
color: hsl(0, 0%, 100%);
position: fixed;
bottom: 50px;
right: 10px;
background: hsl(0, 0%, 10%);
padding: 5px 10px;
text-decoration: none;
-webkit-transform: translate3d(0, 0, 1px);
-webkit-backface-visibility: hidden;
min-width: 50px;
text-align: center;
border: 2px solid black;
}
a.github{
bottom: 10px;
border: 2px solid black;
background: white;
color: black;
}
html #codepen-footer{
-webkit-transition: -webkit-transform .3s cubic-bezier(0.680, -0.550, 0.265, 1.550);
-webkit-transform: translate3d(0, 30px, 0) !important;
}
html:hover #codepen-footer{
-webkit-transform: translate3d(0, 0px, 0) !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment