这将始终失败,因为参数animate_property保持“animate_property”,因为它包裹在一个对象中。如何解决这个问题呢?jQuery动画灵活属性
AnimateIt("height",100);
function AnimateIt(animate_property, val)
{
$(".selector").animate({animate_property:val},500);
}
这将始终失败,因为参数animate_property保持“animate_property”,因为它包裹在一个对象中。如何解决这个问题呢?jQuery动画灵活属性
AnimateIt("height",100);
function AnimateIt(animate_property, val)
{
$(".selector").animate({animate_property:val},500);
}
创建您的对象并在调用animate()
方法之前应用该键和值。您可以使用括号标记设置对象键:
AnimateIt("height",100);
function AnimateIt(animate_property, val)
{
animObj = {};
animObj[animate_property] = val;
$(".selector").animate(animObj ,500);
}
您可以使用eval()
:
AnimateIt("height",100);
function AnimateIt(animate_property, val){
eval('$(".selector").animate({'+animate_property+':'+val+'},500)');
}
或使用对象
AnimateIt("height",100);
function AnimateIt(animate_property, val){
var o={};
o[animate_property] = val;
$(".selector").animate(o,500);
}
呀很好。像魅力一样工作。 – bergman
很高兴有帮助(: – George