【问题标题】:JCrop unfilled selection variablesJCrop 未填充的选择变量
【发布时间】:2017-03-02 17:30:45
【问题描述】:

当我选择一个已经打开默认裁剪区域的图像时,我使用 (setSelect) 方法设置了该区域,如果我在裁剪区域没有任何更改的情况下确认裁剪,则保存图像而没有裁剪导致错误我的数据库,我想我没有填充 JCrop 选择变量。我还注意到它有一个填充这些变量的方法(onSelect: selectcanvas),但它只有在修改裁剪区域后才会调用。

这是我的 JCrop 脚本

$("#canvas").Jcrop({
   minSize: [45, 45],
   maxSize: [1200, 1200],
   bgColor: 'white',
   bgOpacity: .2,
   setSelect: [150, 150, 50, 50],
   aspectRatio: 1,
   allowSelect: false,
   onSelect: selectcanvas,
   onRelease: clearcanvas,
   boxWidth: crop_max_width,
   boxHeight: crop_max_height,
}, function () {
    jcrop_api = this;
});
   clearcanvas();
}

还有 onSelect 方法

function selectcanvas(coords) {
  prefsize = {
    x: Math.round(coords.x),
    y: Math.round(coords.y),
    w: Math.round(coords.w),
    h: Math.round(coords.h)
  };
}

有什么方法可以用一些默认值来启动变量吗?

【问题讨论】:

    标签: javascript jquery jcrop


    【解决方案1】:

    改变这个:

    $("#canvas").Jcrop({
       minSize: [45, 45],
       maxSize: [1200, 1200],
       bgColor: 'white',
       bgOpacity: .2,
       setSelect: [150, 150, 50, 50],
       aspectRatio: 1,
       allowSelect: false,
       onSelect: selectcanvas,
       onRelease: clearcanvas,
       boxWidth: crop_max_width,
       boxHeight: crop_max_height,
    }, function () {
        jcrop_api = this;
    });
       clearcanvas();
    }
    

    到这里:

    $("#canvas").Jcrop({
       onChange: selectcanvas,
       onSelect: selectcanvas,
       onRelease: clearcanvas,
       minSize: [45, 45],
       maxSize: [1200, 1200],
       bgColor: 'white',
       bgOpacity: .2,
       setSelect: [150, 150, 50, 50],
       aspectRatio: 1,
       allowSelect: false,
       boxWidth: crop_max_width,
       boxHeight: crop_max_height,
    }, function () {
        jcrop_api = this;
    });
       clearcanvas();
    }
    

    这将确保首先定义您的函数,这将确保当用户将图像添加到您的输入时,将调用更改事件并初始化您的变量。

    【讨论】:

      猜你喜欢
      • 2017-04-15
      • 1970-01-01
      • 2021-02-02
      • 2017-04-17
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多