Created
November 21, 2011 13:03
-
-
Save meeDamian/1382569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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')); | |
return false; | |
}); | |
}); | |
// do on refresh | |
$(window).load(function() { | |
animateCount($('#listElement')); | |
animateCount($('#listElement2')); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="listElement"> | |
<span class="number">34</span> | |
<strong>Dziwek</strong> | |
</div> | |
<div id="listElement2"> | |
<span class="number">68</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