2012-12-24 50 views
0

我想在秒表等现有数字中添加数字,我的功能是完美添加数字,但我想添加像秒表这样的动画,我试过但我没有得到任何线索完成它。这里有一个working demo如何在动画中添加数字

$('a').click(function() { 
    var val = parseInt($(this).text()); 
    var currentVal = parseInt($('#price').text()) 
    var cal = parseInt(val-currentVal) 
    var club = parseInt($('#price').text()) + cal 
    var bb = $('#price').text(club) 
}) 
})​ 

HTML

<a href="#">10000</a> 
<a href="#">12000</a> 
<a href="#">15000</a> 
<div id="price">10000</div> 
+0

你可以定义像'秒表'的动画吗?我看过的秒表没有动画,数值刚刚出现。 –

+1

像http://stackoverflow.com/questions/4424099/js-jquery-number-increasing-animation和http://stackoverflow.com/questions/5411343/how-to-animate-numbers-using-jquery? –

+0

@RoryMcCrossan:请看这个http://thecodeplayer.com/walkthrough/make-a-stopwatch-using-css3-without-images-or-javascript,你可以看到增加的价值 – jchand

回答

1

使用javascript函数setInterval来做你选择的动画。
view jsfiddle
看看setInterval关于javascript animation为初学者提前使用javascript动画而不使用任何框架。

1

当您设置的.text,认为你可以在这里申请JQuery的动画作为回调的字符串。例如,像这样的东西可能会起作用。改变函数的最后一行:

$('#price').fadeOut('fast', function() { this.text(club); this.fadeIn('fast');}) 

有一个的jsfiddle链接到一个工作示例here更多信息。