为什么这不起作用?如何将函数作为值传递给它?
<div class="div" data-foo="50"></div>
<div class="div" data-foo="100"></div>
$('.div').animate({
width: function() {
return $(this).data('foo');
}
}, 500);
简单地说:是否无法将函数作为$.animate()
中CSS属性的值传递?
答案 0 :(得分:0)
试试这个
$('.div').each(function(){
$(this).animate({width: $(this).data('foo')});
})
至于功能 - 看一下属性哈希的“步骤”键 - http://api.jquery.com/animate/