我有每个函数,里面有带步进函数的动画。 当我尝试调用 $(this) 并调用当前的选择器时 - 它不起作用并给我一些对象(可能是动画步骤函数)
如何到达每个元素选择器的$(this)???
我的代码:
$(".animateNumber").each(function(){
var selector = $(this);
jQuery({ counter: 0 }).animate({
counter: $(this).text()
}, {
step: function() {
// problem: the $(this) not working - if change to `selector` working
$(this).text(Math.ceil(this.counter));
}
});
});
最佳答案
$(".animateNumber").each(function(i,v){
jQuery({ counter: 0 }).animate({
counter: $(v).text()
}, {
step: function() {
$(v).text(Math.ceil(this.counter));
}
});
});
关于javascript - jQuery - 了解步进动画函数内部的 `this`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37095544/