此处解决的问题是一个答案
你可以做这样的事情
http://jsfiddle.net/ZDsMa/94/
使用此代码
var output, started, duration, desired;
// Constants
duration = 5000;
desired = '50';
// Initial setup
output = $('#output');
started = new Date().getTime();
// Animate!
animationTimer = setInterval(function() {
// If the value is what we want, stop animating
// or if the duration has been exceeded, stop animating
if (output.text().trim() === desired || new Date().getTime() - started > duration) {
console.log('animating');
// Generate a random string to use for the next animation step
output.text('' + Math.floor(Math.random() * 990)
);
} else {
console.log('animating');
// Generate a random string to use for the next animation step
output.text('' + Math.floor(Math.random() * 990)
);
}
}, 1000);
我知道代码并不完美,但它确实可以解决我修改了一些其他代码的问题。
谢谢