javascript,在velocity.js中使用变量作为属性名
我试图在velocity.js函数中使用javascript变量设置属性名,但它不太起作用 如果我在没有变量的情况下进行设置,则函数如下所示:javascript,在velocity.js中使用变量作为属性名,javascript,jquery,variables,velocity.js,Javascript,Jquery,Variables,Velocity.js,我试图在velocity.js函数中使用javascript变量设置属性名,但它不太起作用 如果我在没有变量的情况下进行设置,则函数如下所示: $(".pgram-rotator").velocity({ rotateX: '360deg' },600, 'ease-in-out'); 我试图为函数的“rotateX”部分使用一个变量,我得到的是: current_axis = "rotate" + $this.data("axis"); $(".pgram-rotator").v
$(".pgram-rotator").velocity({
rotateX: '360deg'
},600, 'ease-in-out');
我试图为函数的“rotateX”部分使用一个变量,我得到的是:
current_axis = "rotate" + $this.data("axis");
$(".pgram-rotator").velocity({
current_axis: '360deg'
},600, 'ease-in-out');
它实际上不会抛出任何错误,但不会发生旋转。有什么办法让它工作吗?谢谢大家! 您刚刚创建了一个对象,该对象的键为当前_轴,不能将变量用作键 您需要使用括号符号设置键
current_axis = "rotate" + $this.data("axis");
var opts = {};
opts[current_axis] = '360deg';
$(".pgram-rotator").velocity(opts ,600, 'ease-in-out');