2

I'm trying to set a property name with a javascript variable in a velocity.js function, but it's not quite working.

If I set it up with no variable the function looks like:

$(".pgram-rotator").velocity({
  rotateX: '360deg'
},600, 'ease-in-out');

I'm trying to use a variable for the 'rotateX' part of the function, what I have is:

current_axis    = "rotate" + $this.data("axis");

$(".pgram-rotator").velocity({
  current_axis: '360deg'
},600, 'ease-in-out');

it doesn't actually throw any errors, but the rotate doesn't happen. Any ideas on how to get this working? Thank you!

loriensleafs
  • 2,205
  • 9
  • 37
  • 71

1 Answers1

3

You just created an object with the key current_axis, you can not use a variable as a key.

You need to set the key with bracket notation.

current_axis    = "rotate" + $this.data("axis");
var opts = {};
opts[current_axis] = '360deg';
$(".pgram-rotator").velocity(opts ,600, 'ease-in-out');
epascarello
  • 204,599
  • 20
  • 195
  • 236