From e8942be5847bc5b86c780b8c976137b7cd79eca6 Mon Sep 17 00:00:00 2001 From: GaetanNaulin Date: Thu, 14 Apr 2016 09:21:19 +0200 Subject: [PATCH] Adding availability to decrement a number Hi, With this PR, I adding the availability to decrement a number, if data-increment="-xxx" and data-min > data-max. (I think data-start and data-target could be better now). Bye. --- numscroller-1.0.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/numscroller-1.0.js b/numscroller-1.0.js index 1672b77..03792c3 100755 --- a/numscroller-1.0.js +++ b/numscroller-1.0.js @@ -64,11 +64,13 @@ }); }; function numberRoller(slno){ - var min=$('.roller-title-number-'+slno).attr('data-min'); - var max=$('.roller-title-number-'+slno).attr('data-max'); + var min=parseInt($('.roller-title-number-'+slno).attr('data-min')); + var max=parseInt($('.roller-title-number-'+slno).attr('data-max')); var timediff=$('.roller-title-number-'+slno).attr('data-delay'); var increment=$('.roller-title-number-'+slno).attr('data-increment'); var numdiff=max-min; + if(min > max) + numdiff=min-max; var timeout=(timediff*1000)/numdiff; //if(numinc<10){ //increment=Math.floor((timediff*1000)/10); @@ -77,7 +79,7 @@ } function numberRoll(slno,min,max,increment,timeout){//alert(slno+"="+min+"="+max+"="+increment+"="+timeout); - if(min<=max){ + if(min!=max){ $('.roller-title-number-'+slno).html(min); min=parseInt(min)+parseInt(increment); setTimeout(function(){numberRoll(eval(slno),eval(min),eval(max),eval(increment),eval(timeout))},timeout); @@ -85,4 +87,4 @@ $('.roller-title-number-'+slno).html(max); } } -})(jQuery); \ No newline at end of file +})(jQuery);