Below I have a function that animates a div (container) either to the left or the right depending on whether one variable (nextItem) is larger than the other (currentItemRel).
The problem I am having is using the distance variable in the .animate() function.
How can I pass this variable? Currently my JavaScript is breaking so any help would be appreciated.
Thankyou
var distance = (nextItem - currentItemRel) * 1260;
if (nextItem > currentItemRel)
{
$('#container').animate({ left: -=distance }, 1200);
} else if (nextItem < currentItemRel)
{
$('#container').animate({ left: +=distance }, 1200);
};
the += and -= modifier for the jquery animate function, has to be parsed as a string.
Check out this fiddle