
Jcrop Home • Download • Manual • Examples
The API allows developers to create custom Jcrop interaction and behaviors.
Features currently supported by the API
As of v0.9.9, to grab a handle to the Jcrop API, use the "ready" callback:
var jcrop_api;
$('#target').Jcrop(options,function(){
jcrop_api = this;
});
Please note several things about this pattern:
Another pattern for grabbing the Jcrop API, is as follows:
$(window).load(function(){
var api = $.Jcrop(obj,options);
});
Proper values for obj can be a DOM object, a jQuery selector string, or a jQuery object. If the resultant jQuery object contains multiple elements, the first one is used. Options may be specified as the second parameter, see example below.
Important note: you must call the API Invocation Method from within $(window).load() or unexpected behavior may occur.
| setSelect(array) | Set selection, format: [ x,y,x2,y2 ] |
|---|---|
| animateTo(array) | Animate selection to new selection, format: [ x,y,x2,y2 ] |
Notice: If you are using scaled images these calls will set based on the true image size.
The selection can also be cleared:
| release() | Release current selection |
|---|
The Jcrop API provides an alternative to using callbacks by providing methods to query the current selection values.
| tellSelect() | Query current selection values (true size) |
|---|---|
| tellScaled() | Query current selection values (interface) |
Jcrop can be disabled and re-enabled using these API calls:
| disable() | Disables Jcrop interactivity |
|---|---|
| enable() | Enables Jcrop interactivity |
Jcrop can also be completely removed from the image:
| destroy() | Remove Jcrop entirely |
|---|
jQuery(function($){
var jcrop_api;
$('#target').Jcrop({
bgColor: 'red'
},function(){
jcrop_api = this;
});
$('#animbutton').click(function(e){
jcrop_api.animateTo([ 120,120,80,80 ]);
return false;
});
$('#delselect').click(function(e){
jcrop_api.release();
return false;
});
});