Skip to content

Instantly share code, notes, and snippets.

@meeDamian
Created November 21, 2011 13:05
Show Gist options
  • Save meeDamian/1382579 to your computer and use it in GitHub Desktop.
Save meeDamian/1382579 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript">
function animateCount($node) {
// nodes & values
var $val = $node.find('.number');
var val = parseInt($val.text());
$val.text('0');
// time variables
var current = 0;
var miliseconds = 2000;
var step = (val<120) ? 1 : val/40;
var counter = setInterval(function(){
$val.text(current);
current = parseInt(current) + parseInt(step);
if(current+step >= val) {
clearInterval(counter);
$val.text(val);
}
}, miliseconds / (val/step));
return false;
}
// do on click
$(function() {
$('#go').click( function(){
animateCount($('#listElement'));
animateCount($('#listElement2'));
animateCount($('#listElement3'));
animateCount($('#listElement4'));
return false;
});
});
// do on refresh
$(window).load(function() {
animateCount($('#listElement'));
animateCount($('#listElement2'));
animateCount($('#listElement3'));
animateCount($('#listElement4'));
});
</script>
</head>
<body>
<div id="listElement">
<span class="number">34</span>
<strong>Dziwek</strong>
</div>
<div id="listElement2">
<span class="number">680</span>
<strong>Dziwek</strong>
</div>
<div id="listElement3">
<span class="number">4</span>
<strong>Dziwek</strong>
</div>
<div id="listElement4">
<span class="number">121</span>
<strong>Dziwek</strong>
</div>
<a href="#" id="go">asdasd</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment