0

Can I possibly animate multiple variable values in a single animation? I would like to animate two variable values from this value to that value.

In this code, I would want the x and y values to animate from a given value to another value but I can only do it with the x. (Code was based from an answer here but would like some help in doing so with multiple values: jquery "animate" variable value)

$({someValue: 0}).animate({someValue: -2147.141601481341}, {
    duration: 5000,
    step: function() { 
        mainMap.pan({x: someValue, y: -5937.031428375433})
    }
});

1 Answer 1

1

Just add multiple properties to your Object. Try it:

//initial values          end values
$({x: 0, y: 10}).animate({x: 10, y: 0}, {
    duration: 5000,
    step: function() { 
        $('#x').text(Math.round(this.x));
        $('#y').text(Math.round(this.y));
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

x: <span id="x"></span> <br/>
y: <span id="y"></span>

Your code should look something like:

$({x: 0, y: 0}).animate({x: -2147.141601481341, y: -5937.031428375433}, {
    duration: 5000,
    step: function() { 
        mainMap.pan(this)
        // or mainMap.pan({x: this.x, y: this.y, foo: "bar"})
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Oh my God thank you it worked. Thank you so much. Thank you.

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.