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})
    }
});
Community
  • 1
  • 1
zangetsu
  • 127
  • 8

1 Answers1

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"})
    }
});
blex
  • 24,941
  • 5
  • 39
  • 72