繁体   English   中英

如何获取事件缩放的值并从输入中更改它

[英]How I can get the values of the event zoom and change it from an input

我的情况是这样的:

我使用这个库:

http://fengyuanchen.github.io/cropper/

如我所见,我可以使用事件缩放来检索缩放图像的值。 因此,我想知道如何获取它并从诸如selectable之类的输入中更改它。

var $content = $(c_s),
    $image = $(p_s),
    $dataWidth = $(i_w_s),
    $dataHeight = $(i_h_s),
    $dataX = $(i_x_s),
    $dataY = $(i_y_s),
    options = {
        autoCropArea: 1,
        strict: true,
        guides: true,
        highlight: true,
        dragCrop: false,
        cropBoxMovable: false,
        cropBoxResizable: false,
        movable: true,
        background: true,
        minContainerWidth: 340,
        minContainerHeight: 226,
        minCanvasWidth: 340,
        minCanvasHeight:226,
        minCropBoxWidth: 340,
        minCropBoxHeight:226,
        aspectRatio: radio,
        crop: function (data) {
            $dataX.val(Math.round(data.x));
            $dataY.val(Math.round(data.y));
            $dataHeight.val(Math.round(data.height));
            $dataWidth.val(Math.round(data.width));
        }
    };

$image.on({
  'zoom.cropper': function (e) {
    console.log(e.type, e.ratio);
  }
}).cropper(options);

这是该库的文档https://github.com/fengyuanchen/cropper#zoomcropper

在代码的最后,您可以看到我有一个console.log来检查是否有东西,但是我的Firebug控制台没有任何东西。

感谢你所做的一切,

文献资料

$().on('zoom.cropper', function (e) {
  var maxRatio = 10;
  var imageData = $(this).cropper('getImageData');
  var currentRatio = imageData.width / imageData.naturalWidth;

  // Zoom in
  if (e.ratio > 0 && currentRatio > maxRatio) {

    // Prevent zoom in
    e.preventDefault();

    // Fit the max zoom ratio
    $(this).cropper('setCanvasData', {
      width: imageData.naturalWidth * maxRatio
    });
  }

  // Zoom out
  // ...
});

您的密码

$image.on({
  'zoom.cropper': function (e) {
    console.log(e.type, e.ratio);
  }
}).cropper(options);

看到区别..语法

它应该是

$image.cropper(options);
$image.on('zoom.cropper', function (e) {
    console.log("Here "+e);
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM