简体   繁体   English

jQuery Cropper插件:缩放事件时,图像保持在左上方

[英]jQuery Cropper Plugin: Keep Image on top-left on zoom event

I'm using this awesome plugin "Cropper" to upload Images of a specific size. 我正在使用这个很棒的插件“ Cropper”上传特定大小的图片。 So far, evertything works fine, but: 到目前为止,一切正常,但是:

When I call: 当我打电话时:

    function moveImageToZero() {

    $("#target").cropper('moveTo',0,0);
}

from a button click or inside the on('ready') event of the cropper element like this 通过单击按钮或像这样的裁剪器元素的on('ready')事件内部

    $("#target").on('ready', function () {
        moveImageToZero();
    });

the canvas DOES move to the top-left corner. 画布确实移到左上角。

Anyway, calling the 'moveTo' function from inside an Event-Handler of a cropper element: 无论如何,从cropper元素的事件处理程序内部调用“ moveTo”函数:

$("#target").on('zoom',function () {
            moveImageToZero();
        });

nothing actually happens. 实际上没有任何反应。

Functions are invoked properly and do not throw errors or exceptions. 函数会被正确调用,并且不会引发错误或异常。

Does someone have a solution for this? 有人对此有解决方案吗?

I'm trying to keep the Image/Canvas always fixed to the top-left corner. 我试图将图像/画布始终固定在左上角。

Any help is highly appreciated! 任何帮助深表感谢!

Try this: 尝试这个:

 $("#target").on('ready', function () {
    moveImageToZero(this.cropper); 
});

function moveImageToZero(cropper) {

 cropper('moveTo',0,0);
}

I'm not sure it works, but when I used cropper last time, I used native js cropper lib, and code looked like that: 我不确定它是否有效,但是当我上次使用cropper时,我使用了本地js cropper lib,代码如下所示:

const cropper = new Cropper(imageEl, {
        aspectRatio: this.aspectRatio 
        background: false,
        rotatable: true,
        zoomable: !!this.aspectRatio,
        movable: false,
        checkCrossOrigin: false,
        crop: (e) => {
            // on cropp event

        },
        ready: function () {
            self.cropper = this.cropper; // so I use it outside in my function/class
        }
    });

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

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