mheavers
mheavers

Reputation: 30158

syntax error when using a variable in jquery animate function

I can't figure out how to use a variable in jquery's animate function. I'm trying to do this:

$('#trends_holder').animate({'left' : left_indent}, 300);

where left_indent is a variable I've created elsewhere. What am I doing wrong here?

If I output this, I get "invalid token , " and the output code looks like this:

$('#trends_holder').animate(, 300);

If I trace this:

alert (item_count + " | " + item_width + " | " + item_count * item_width);

I get a proper value for all of these. But then if I assign a variable to it, it doesn't work:

var indent_val = -(item_count * item_width);
$('#trends_holder').animate({'left' : indent_val}, 300);

Upvotes: 0

Views: 535

Answers (1)

ezmilhouse
ezmilhouse

Reputation: 9121

find working fiddle here: http://jsfiddle.net/ezmilhouse/GqXmy/1/

var left_indent = 300;
$('#trends_holder').animate({'left' : left_indent}, 300);

Upvotes: 2

Related Questions