JCrop inconsistent click behavior with and without aspectRatio set

169 Views Asked by At

If you set minSize, Jcrop seems to have different click behavior, depending on whether or not you are additionally setting the aspectRatio option. If you set minSize + aspectRatio, you have to click and drag to get the crop box to to display; if you set minSize without setting aspectRatio, all you have to do is click to get the crop box.

This is easy to reproduce on JCrop's advanced demo page (http://deepliquid.com/projects/Jcrop/demos.php?demo=advanced):

  • If you have "Allow new selections" and "minSize/maxSize setting" checked, all you have to do is click inside the image to get the crop box to display.
  • If you have "Allow new selections," minSize/maxSize setting," and "Aspect ratio" checked, then you have to click and drag inside the image to get the crop box to display.

Has anyone had any luck getting the crop box to display with just a click in both cases?

1

There are 1 best solutions below

0
On

You could try calling the setSelect API method on the click event. The x and y coordinates are available to you, you just need to specify a width and height.

For example:

jcrop_api.setOptions({
  setSelect:    [10,10,100,100],
  aspectRatio:2
});

where jcrop_api is initialized when "attaching" jcrop to an image:

$j(function($) {
    $('#leftImg').Jcrop({
        onSelect: checkSelection,
        onChange: checkSelection,
        onRelease: wholeImage,
        bgOpacity:0.2,
        bgColor:"white"
        },function(){jcrop_api = this;}
    );
});