JCrop检查是否选择了区域

JCrop Check if Region Selected

本文关键字:区域 选择 是否 检查 JCrop      更新时间:2023-09-26

有人能告诉我如何在JCrop中检查是否选择了要裁剪的区域吗?

我希望在API中有一个布尔函数,但我看不到这样的东西。我尝试使用updatecoords函数,但即使没有选择,x、y、w和h也会被设置。

这是我的实例化:

var jcrop_api;
$('#profile_crop').Jcrop({onSelect: updateCoords, setSelect: [0, 542, 671, 0], boxWidth: 542, boxHeight: 671, aspectRatio: 542/671},
    function() {
         jcrop_api = this; 
    });

您必须手动检测何时有选择,因此使用onRelease处理程序。来自API:

var jcrop_api;
var selected;
$('#profile_crop').Jcrop({onSelect: showCoords, onRelease: releaseCoords, setSelect: [0, 542, 671, 0], boxWidth: 542, boxHeight: 671, aspectRatio: 542/671},
  function() {
    jcrop_api = this; 
  }
);
function showCoords(c){
  selected = true;
  // variables can be accessed here as
  // c.x, c.y, c.x2, c.y2, c.w, c.h
};
function releaseCoords(c){
  selected = false;
  // variables can be accessed here as
  // c.x, c.y, c.x2, c.y2, c.w, c.h
};

如果我没有回答你的问题,就让我知道!