Search code examples
javascriptjcrop

Getting the Jcrop coordinates back into Jcrop through javascript variable?


If I set a variable like this:

var coords = jcrop_api.tellSelect();

It returns my current Jcrop selections coordinates in an x,y,x2,y2,h,w format.

Now if I want to set my coordinates back to that, I could go:

jcrop_api.animateTo(coords)

But the animateTo function only takes an array of 4, [x, y, w, h] When I try to do the above way, it eventually breaks the code. So how do I change my variable coords to fit this format?

Thanks


Solution

  • The API functions you mention at least at the 0.9.12 version of the plugin..

    jcrop_api.tellSelect() returns an object like this:

    {
       x: 0,
       y: 0,
       x2: 10,
       y2: 10,
       w: 10,
       h:10
    }
    

    and jcrop_api.animateTo needs one array like [x,y,x2,y2], so, try this:

    var c = jcrop_api.tellSelect();
    
    jcrop_api.animateTo([c.x,c.y, c.x2, c.y2]);