Cropperjs 设置位置

huangapple go评论89阅读模式
英文:

Cropperjs set position

问题

我正在尝试将裁剪器的默认位置设置为以下内容:

ngAfterViewInit(): void {
  const image = this.imageElement.nativeElement as HTMLImageElement;
  image.onload = () => {
    this.cropper = new Cropper(image, {
      checkCrossOrigin: true,
      checkOrientation: true,
      dragMode: 'none',
      zoomable: false,
      background: false,
      data: {
        width: 240,
        height: 130
      }
    });
  };
}

我尝试添加以下方式来设置裁剪框数据:

ngAfterViewInit(): void {
  const image = this.imageElement.nativeElement as HTMLImageElement;
  image.onload = () => {
    this.cropper = new Cropper(image, {
      checkCrossOrigin: true,
      checkOrientation: true,
      dragMode: 'none',
      zoomable: false,
      background: false,
      data: {
        width: 240,
        height: 130
      }
    });
    this.cropper.setCropBoxData({
       left: 100,
       top: 100
    });
  };
}

但它不起作用。我还尝试使用setData()方法。同样不起作用。

英文:

I'm trying to set default position to cropper. This is what I have:

  ngAfterViewInit(): void {
    const image = this.imageElement.nativeElement as HTMLImageElement;
    image.onload = () => {
      this.cropper = new Cropper(image, {
        checkCrossOrigin: true,
        checkOrientation: true,
        dragMode: 'none',
        zoomable: false,
        background: false,
        data: {
          width: 240,
          height: 130
        }
      });
    };
  }

I tried adding setCropBoxData like this:

ngAfterViewInit(): void {
    const image = this.imageElement.nativeElement as HTMLImageElement;
    image.onload = () => {
      this.cropper = new Cropper(image, {
        checkCrossOrigin: true,
        checkOrientation: true,
        dragMode: 'none',
        zoomable: false,
        background: false,
        data: {
          width: 240,
          height: 130
        }
      });
      this.cropper.setCropBoxData({
         left: 100,
         right: 100
      })
    };
  }

But it's not working. I also tried using setData() method. Also not working.

答案1

得分: 0

找到解决方案:

ngAfterViewInit(): void {
  const image = this.imageElement.nativeElement as HTMLImageElement;
  image.onload = () => {
    this.cropper = new Cropper(image, {
      checkCrossOrigin: true,
      checkOrientation: true,
      dragMode: 'none',
      zoomable: false,
      background: false,
      data: {
        width: 240,
        height: 130,
        x: value,
        y: value
      }
    });
  };
}

在数据对象中添加了 x 和 y 属性。

英文:

Found solution:

ngAfterViewInit(): void {
    const image = this.imageElement.nativeElement as HTMLImageElement;
    image.onload = () => {
      this.cropper = new Cropper(image, {
        checkCrossOrigin: true,
        checkOrientation: true,
        dragMode: 'none',
        zoomable: false,
        background: false,
        data: {
          width: 240,
          height: 130,
          x: value,
          y: value
        }
      });
    };
  }

Added x,y properties in data object.

huangapple
  • 本文由 发表于 2023年6月15日 21:53:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483204.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定