1

I was wondering how to use gathered variables within the jQuery animate function. Here is the code that I was working on:

var size = $("#myTwitter").width();

    var slidelength = (686 - size)*(-1);

    var slidelength = slidelength.toString();

    var margin = "'margin-left:' '";

    var after = "px'";

    var output = margin.concat(slidelength, after);

    $("#twitWrap").mouseenter(function(){

        $("#myTwitter").stop(0).animate(output, 5000);

    });

    $("#twitWrap").mouseleave(function(){

        $("#myTwitter").stop(0).animate({"margin-left": "0px"}, 5000);

    });

as you can tell its not working - still no idea why though.

1 Answer 1

6

You don't need to do anything special.

$("#myTwitter").stop(0).animate({"margin-left":  slidelength }, 5000);

If "margin-left" needs to be dynamic, you can do...

var options = {};

options[property] = value;

$("#myTwitter").stop(0).animate(options, 5000);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.