On 31/07/2007, at 12:58 AM, Benjamin Sterling wrote:
Question 2:
I want to make the above code more dynamic, I am allowing for a option to be passed in to change the direction of the animation, but when I do:

                            newDirection = 'left';
$this.animate({ newDirection:-208,'top': 15},

It left animation does not work at all.

This sort of thing has happened to me also - I wrestled with it for ages. I was trying to make an element fixed position left or right dynamically using .css(). So it wasn't animate() but it may work similarly. I ended up doing something hacky like this (below) but I was still frustrated that I didn't understand what was happening:

var leftAlign = true;
var posiOffset = 10;
var c = { width : 100px};
c[leftAlign ? 'left' : 'right' ] = posiOffset +'px';
$('#el').css(c);

So basically, setting the object property via object[dynamicProperty] worked whilst object = {dynamicProperty : value} didn't.

If you figure out why this happens, I'll be very interested to hear about it.

Cheers
Joel Birch.

Reply via email to