JSFiddle - React, Tailwind, and code Playground
by tjerabek
HTML
<div class="counter">
<span class="number">0</span>
</div>
<a href="#" class="counter-increse">Increse</a>
CSS
body{
padding: 50px;
font-family: Arial;
font-size: 90%;
}
.counter-increse{
display: inline-block;
padding: 0 10px;
line-height: 40px;
}
.counter{
float: left;
font-size: 110%;
width: 40px;
height: 40px;
background: #58544F;
font-weight: bold;
color: white;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
overflow: hidden;
}
.number{
line-height: 40px;
display: block;
width: 40px;
text-align: center;
text-shadow: 0px 1px 1px #1a1a1a;
-webkit-transition: all 400ms ease;
-moz-transition: all 400ms ease;
-ms-transition: all 400ms ease;
-o-transition: all 400ms ease;
transition: all 400ms ease;
}
.number.top{
margin-top: -40px;
}
.number.center{
margin-top: 0;
}
.number.bottom{
margin-top: 0;
}
JavaScript
$(document).ready(function(){
var counter = 0;
$('.counter .number').addClass('center');
var $top = $('<span class="number top">'+(counter + 1)+'</span>');
$('.counter .number.center').before($top);
counter++;
$('.counter-increse').click(function(){
counter++;
var $newTop = $('<span class="number top">'+counter+'</span>');
$('.counter .number.center').addClass('bottom');
$('.counter .number.center').removeClass('center');
$('.counter .number.top').addClass('center');
$('.counter .number.top').removeClass('top');
$('.counter .number.center').before($newTop);
return false;
});
});