forked from jesucarr/jOdometer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.jodometer.min.js
11 lines (11 loc) · 2.77 KB
/
jquery.jodometer.min.js
1
2
3
4
5
6
7
8
9
10
11
/*
* jOdometer (1.0) // 2008.03.17 // <http://www.frontendmatters.com/projects/jquery-plugins/>
*
* REQUIRES jQuery 1.2.3+ <http://jquery.com/>
*
* Copyright (c) 2008 TrafficBroker <http://www.trafficbroker.co.uk>
* Licensed under GPL and MIT licenses
*
* @author Suso Guez (Jesus Carrera Rodriguez) <suso.guez@frontendmatters.com>
*/
(function(A){A.fn.jOdometer=function(B){B=A.extend({},A.fn.jOdometer.defaults,B);return this.each(function(){var O=A(this);var D=-B.heightNumber;var C=parseFloat(B.counterStart);var M=[];var Q=[];var F=String(B.counterStart).split(".");var H=0;var G=0;if(F[1]){var I=0;for(var J=F[1].length-1;J>-1;J--){Q[J]=F[1].charAt(J);A(this).append('<img style="position:absolute; right:'+(I*B.widthNumber+B.offsetRight+I*B.spaceNumbers)+"px; top:"+((parseInt(Q[J])*B.heightNumber*-1)+D)+'px;" class="jodometer_decimal_'+J+'" src="'+B.numbersImage+'" alt="Decimal '+(J+1)+'" />');I++}A(this).append('<div style="position:absolute; width:'+B.widthDot+"px; height:"+B.heightNumber+"px; background:url("+B.numbersImage+") no-repeat center bottom; right:"+(F[1].length*B.widthNumber+B.offsetRight+F[1].length*B.spaceNumbers)+'px;" class="jodometer_dot"></div>');H=F[1].length;G=B.widthDot}var E=F[0];var I=E.length-1;for(var J=0;J<E.length;J++){M[J]=E.charAt(I);A(this).append('<img style="position:absolute; right:'+(J*B.widthNumber+H*B.widthNumber+G+B.offsetRight+H*B.spaceNumbers+J*B.spaceNumbers+B.spaceNumbers)+"px; top:"+((parseInt(M[J])*B.heightNumber*-1)+D)+'px;" class="jodometer_integer_'+J+'" src="'+B.numbersImage+'" alt="Integer '+(J+1)+'" />');I--}if(parseFloat(B.counterStart)!=B.counterEnd||(B.counterEnd.toString()=="false"&&parseFloat(B.counterStart)==0)){var P=setInterval(N,B.delayTime)}function N(){L(C);C=C+B.increment;if(B.counterEnd!=false&&C>=B.counterEnd){clearInterval(P);L(B.counterEnd)}}function L(R){F=String(R).split(".");if(Q.length>0){for(J=0;J<Q.length;J++){oldDigit=Q[J];if(F[1]){Q[J]=F[1].charAt(J)}if(Q[J]==""){Q[J]="0"}K(A(".jodometer_decimal_"+J,O),parseInt(Q[J]),parseInt(oldDigit))}}E=F[0];I=E.length-1;for(J=0;J<M.length;J++){oldDigit=M[J];M[J]=E.charAt(I);if(M[J]==""){M[J]="0"}K(A(".jodometer_integer_"+J,O),parseInt(M[J]),parseInt(oldDigit));I--}}function K(S,R,T){if(R!=T){S.stop();if(R==0){S.animate({top:(10*B.heightNumber*-1)+D},B.speed,B.easing).animate({top:D},1,"linear")}else{if(R<T){S.animate({top:(10*B.heightNumber*-1)+D},B.speed*((10-T)/10),"linear").animate({top:D},1,"linear").animate({top:(R*B.heightNumber*-1)+D},B.speed*T/10,B.easing)}else{S.animate({top:(R*B.heightNumber*-1)+D},B.speed,B.easing)}}}}})};A.fn.jOdometer.defaults={counterStart:"0000.00",counterEnd:false,delayTime:1000,increment:0.01,speed:500,easing:"swing",numbersImage:"/images/jodometer-numbers.png",heightNumber:31,widthNumber:14,offsetRight:0,spaceNumbers:0,widthDot:10}})(jQuery);