views:

38

answers:

2

I have written a script to slide a div horizontally and stop at a specific margin-left value.

The margin left depends on the link which was clicked, so I have used a calculation to find that specific value. When i try to pass the variable into the .animate({"margin-left":value},"slow");

Here is the code

    var marginLeft = parseInt((linkClick * 995)-995)+"px";
    $("div_to_animate").animate({
      "margin-left":marginLeft},"slow");

I have used the code below to ensure that it is returning the correct value

alert(marginLeft);

Any suggestions?

Thanks

A: 

The CSS selector you use in your example code isn't correct. If your HTML looks like this:

<div id="div_to_animate">...</div> 

Your selector should be:

$("#div_to_animate").animate({"margin-left":marginLeft},"slow");
calvinf
sorry, that CSS selector was just an example.
bell
A: 

Problem solved, I needed to add a "-" symbol before the marginLeft variable to make it a negative margin.

Thanks for the advice.

bell