英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论