作为一个例子,我以 jQuery 动画函数为例: 正常情况下它的工作原理是这样的:
$("#div1").animate({
width: '300px',
}, 1000, function() {
console.log("animate 1 done");
});
我想要这样的:
animateConfig = [{
width: '300px',
}, 1000, function() {
console.log("animate1 done");
}];
startAnimate($("#div1"), animateConfig);
function startAnimate(obj, animateConfig) {
console.log(animateConfig);
obj.animate(animateConfig);
}
也是一个 fiddle :http://fiddle.jshell.net/hVXKM/1/
最佳答案
尝试:
obj.animate.apply(obj, animateConfig);
关于javascript - 为具有 1 个变量/对象的函数提供多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18542923/