// 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 })
所以,代码已经发展了一些。
此question。
我在函数中包含了增量。它由用户向下滚动(通过waypoint.js)触发。但是,我怎样才能让它动画一次,而不是每次都有人滚动它。想法?
答案 0 :(得分:0)
您应该能够传递triggerOnce参数
$('.scene06').waypoint(function() {
{
stepNum();
},
{
offset: 400,
triggerOnce: true
});