Skip to content

Instantly share code, notes, and snippets.

@meeDamian
Created November 21, 2011 12:54
Show Gist options
  • Save meeDamian/1382552 to your computer and use it in GitHub Desktop.
Save meeDamian/1382552 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.html('0');
// time variables
var current = 0;
var miliseconds = 2000;
var counter = setInterval(function(){
if(current >= val) clearInterval(counter);
$val.text(current);
current = parseInt(current) + 1;
}, miliseconds / val);
return false;
}
// do on click
$(function() {
$('#go').click( function(){ return animateCount($('#listElement')); });
});
// do on refresh
$(window).load(function() { animateCount($('#listElement')); });
</script>
</head>
<body>
<div id="listElement">
<span class="number">30</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