【发布时间】:2014-07-14 21:37:18
【问题描述】:
好的,这看起来应该很简单,但我想不通。我有来自另一位开发人员的这段代码,我的任务是更改为在页面加载而不是滚动时触发。我已经尝试更改我能想到的所有内容(例如将.bind 更改为.load 和jQuery(this).bind('inview', function(event,visible) 更改为$(document).ready(function()),但没有任何效果。我该怎么做才能让这些数字仅在初始页面加载时进行动画处理?
// Animate any number
jQuery('.animateNumber').each(function(){
var value = new Number;
// Grab contents of element and turn it into a number
value = jQuery(this).text();
value = parseInt(value);
// Set the starting text to 0
jQuery(this).text('0');
// Animate to correct value
jQuery(this).bind('inview', function(event,visible) {
if(visible == true) {
jQuery(this).animateNumber(
{
number: value,
},
1000
)
}
});
});
更新
我已将代码更改为以下代码,它在 Firefox 中运行良好,但在 Chrome 中没有动画效果。有人知道为什么会这样吗?
// Animate any number
jQuery('.animateNumber').each(function(){
var value = new Number;
// Grab contents of element and turn it into a number
value = jQuery(this).text();
value = parseInt(value);
// Set the starting text to 0
jQuery(this).text('0');
// Animate to correct value
jQuery(this).animateNumber(
{
number: value
},
1000
);
});
【问题讨论】:
标签: javascript jquery function jquery-animate bind