Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript,在velocity.js中使用变量作为属性名_Javascript_Jquery_Variables_Velocity.js - Fatal编程技术网

javascript,在velocity.js中使用变量作为属性名

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

我试图在velocity.js函数中使用javascript变量设置属性名,但它不太起作用

如果我在没有变量的情况下进行设置,则函数如下所示:

$(".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');