如何使用Jquery对数字进行动画处理 [英] how to animate numbers using Jquery
本文介绍了如何使用Jquery对数字进行动画处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试使一个说$ 233到$ 250的动画或从250变到233的动画,我不想将233替换为250,而是想要一种相反的效果,并且在滚动数字时也需要缩放效果. 我是Jquery的新手,将不胜感激任何帮助.
I am trying to animate a say $233 to $250 or decreasing from 250 to 233 ,i dont want to replace 233 by 250 instead i want a counter kind of effect and at the time of scrolling numbers zoom effect is also required. i am new to Jquery any help would be highly appreciated.
推荐答案
HTML
<button id="start">Start</button>
<button id="reset">Reset</button>
<input id="counter" value="233"/>
JavaScript
$(function ()
{
var $start = $('#start'),
start = $start.get(0),
$reset = $('#reset'),
reset = $reset.get(0),
$counter = $('#counter'),
startVal = $counter.text(),
currentVal = startVal,
endVal = 250,
prefix = '$',
fontSize = $counter.css('font-size');
$start.click(function ()
{
this.disabled = true;
var i = setInterval(function ()
{
if (currentVal === endVal)
{
clearInterval(i);
reset.disabled = false;
$counter.animate({fontSize: fontSize});
}
else
{
currentVal++;
$counter.text(prefix+currentVal).animate({fontSize: '+=1'}, 100);
}
}, 100);
});
$reset.click(function ()
{
$counter.text(prefix + startVal);
this.disabled = true;
start.disabled = false;
}).click();
});
这篇关于如何使用Jquery对数字进行动画处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文