I am having trouble to get this done. What i want to achieve, is to display each div's height value, on its top. I'd also like to see those numbers animated , counting up when div height grows. So far, it displays same value for each one, and none of it is accurate. I use this graph just as an example in UI design, so that the div heights are randomly generated on button toggle.
I am really new to the Jquery, as in all other forms of web programing, so i can't assume what is wrong!
Thanks,
HTML:
<div class="statistics" >Statistics</div>
<ul class="statisticsGraph">
<li><div class="statLine"><span class="statCircle"></span><span class="number"></span></div></li>
<li><div class="statLine"><span class="statCircle"></span><span class="number"></span></div></li>
<li><div class="statLine"><span class="statCircle"></span><span class="number"></span></div></li>
<li><div class="statLine"><span class="statCircle"></span><span class="number"></span></div></li>
<li><div class="statLine"><span class="statCircle"></span><span class="number"></span></div></li>
<li><div class="statLine"><span class="statCircle"></span><span class="number"></span></div></li>
<li><div class="statLine"><span class="statCircle"></span><span class="number"></span></div></li>
</ul>
CSS:
.statistics {
position: relative;
display: block;
width: 100%;
border-bottom: 1px solid #000;
height: 30px;
background: #fff;
background: #000;
color: #fff;
padding:20px 20px;
font-size: 20px;
text-decoration: none;
text-transform: uppercase;
font-weight: bold;
}
ul.statisticsGraph li {
position: relative;
display: inline-block;
float: right;
width: 10%;
margin: 10px 5px 0 0;
height: 230px;
}
.statLine {
position: absolute;
display: block;
background: red;
width: 5px;
bottom: 0px;
overflow:visible !important;
}
.statCircle {
position: relative;
display: block;
width: 8px;
height:8px;
left: -8px;
border-radius: 50%;
background: yellow;
border: 6px solid red;
}
.number {
position: relative;
display: inline-block;
width: 30px;
height: 15px;
color: #000;
padding: 4px;
font-size: 18px;
top: -60px;
left: -17px;
border-radius: 3px;
border: 1px solid #ffd800;
}
JQUERY:
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
$('.statistics').on('click',function(){
$('.statLine').each(function(){
var statsValue = $('.statLine').height();
$(this).animate({'height':'0'}, function(){
$(this).animate({'height' : getRandomInt(0,200)});
$('.number').text(statsValue);
});
});
});
LIVE EXAMPLE: