function Counter(obj){
console.log('OBJ:', obj);
var number = "311.2 $";
console.log("N:", number);
// clear the HTML element
obj.empty();
console.log('OBJ EMP:', obj);
// create an array from the text, prepare to identify which characters in the string are numbers
var numChars = number.split("");
var numArray = [];
var setOfNumbers = [0,1,2,3,4,5,6,7,8,9];
// for each number, create the animation elements
for(var i=0; i<numChars.length; i++) {
console.log("obj", obj);
if (setOfNumbers.indexOf(parseInt(numChars[i], 10)) !== -1) {
obj.append('<span class="digit-con"><span class="digit'+numArray.length+'">0<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br></span></span>');
numArray[numArray.length] = parseInt(numChars[i], 10);
} else {
obj.append('<span>'+numChars[i]+'</span>');
}
}
// determine the height of each number for the animation
var increment = obj.find('.digit-con').outerHeight();
console.log("increment", increment);
var speed = 2000;
// animate each number
for(var i=0; i<numArray.length; i++) {
obj.find('.digit'+i).animate({top: -(increment * numArray[i])}, Math.round(speed / (1 + (i * 0.333))));
}
}
$("#animate").click(function(){
$('.number').eq(0).text($('.number').attr('data-number'));
Counter($('.number').eq(0));
console.log("AA", $('.number').eq(0));
});
function animateCounter(ev) {
console.log("animate", ev);
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.