// Animate the element's value from x to y:
function stepNum () {
$({someValue: 40000}).animate({someValue: 45000}, {
duration: 3000,
easing:'swing', // can be anything
step: function() { // called on every step
// Update the element's text with rounded-up value:
$('#el').text(commaSeparateNumber(Math.round(this.someValue)));
}
});
function commaSeparateNumber(val){
while (/(\d+)(\d{3})/.test(val.toString())){
val = val.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
return val;
}
}
$('.scene06').waypoint(function() {
stepNum();
}, { offset: 400 })
所以,代码已经进化了一点。
既然这个问题。
我已经将增量包装在一个函数中。它是由用户向下滚动(通过waypoint.js)触发的。但是我怎样才能让它只动画一次而不是每次有人滚动它时重复。想法?