要插入.animate(变量:'50px')的代码,表示将属性设置为变量。在jquery

时间:2013-08-06 09:04:54

标签: jquery

var thetop = "top";

// create the object literal
var aniArgs = {};

// Assign the variable property name with a value of 10
aniArgs[thetop] = 10; 

// Pass the resulting object to the animate method
<something>.stop().animate(
    aniArgs, 10  
);  

我只想把top,right,left作为一个属性,而不是像上面代码那样整个东西

2 个答案:

答案 0 :(得分:0)

$('selector').stop().animate({top:100, left:100});

答案 1 :(得分:0)

这些行中的东西

var arg = {};

arg["top"]= "200px";

$('div').animate(arg,2000);

<强> Check Fiddle