Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我需要防止拖动和缩放可以旋转的对象_Javascript_Canvas_Fabricjs - Fatal编程技术网

Javascript 我需要防止拖动和缩放可以旋转的对象

Javascript 我需要防止拖动和缩放可以旋转的对象,javascript,canvas,fabricjs,Javascript,Canvas,Fabricjs,我有一张画布,上面有一个矩形槽,上面有图像。在矩形外,显示的是背景,而不是图像(因此它正在裁剪图像)。我试图防止图像不覆盖裁剪矩形,图像应该总是更大,完全覆盖矩形。我在直线图像/矩形上工作,但当涉及旋转时,我无法使其工作 我已经使用了这个问题中的代码,使其能够在直图像上工作: canvas.on('object:moving',(事件:any)=>{ //此eventlistener确保运动图像不会使其占位符区域未覆盖 // const activeObject=event.target; /

我有一张画布,上面有一个矩形槽,上面有图像。在矩形外,显示的是背景,而不是图像(因此它正在裁剪图像)。我试图防止图像不覆盖裁剪矩形,图像应该总是更大,完全覆盖矩形。我在直线图像/矩形上工作,但当涉及旋转时,我无法使其工作

我已经使用了这个问题中的代码,使其能够在直图像上工作:

canvas.on('object:moving',(事件:any)=>{
//此eventlistener确保运动图像不会使其占位符区域未覆盖
//
const activeObject=event.target;
//裁剪矩形
const containerRect=retrieveObjectFromCanvas(this.state.canvas,`${this.selectedImage.value.id}-container`);
//应用当前移动操作的新坐标
activeObject.setCoords();
const newCoords=activeObject.getCoords();
const containerCoords=containerRect.getCoords();
//左
if(newCoords[0].x>=containerCoords[0].x){
activeObject.left=(containerRect.left-(containerRect.width/2)+(activeObject.width*activeObject.scaleX)/2);
}
//顶
if(newCoords[0].y>=containerCoords[0].y){
activeObject.top=(containerRect.top-(containerRect.height/2)+(activeObject.height*activeObject.scaleY)/2);
}
//对
if(newCoords[2].x=containerCoords[0].x){
const newScale=(boundingRect.width)/activeObject.width;
activeObject.scaleX=newScale;
activeObject.left=(containerRect.left-(containerRect.width/2)+(activeObject.width*activeObject.scaleX)/2);
}
//顶
角点=['tl','mt','tr'];
if(包括(corners,event.transform.corner)和&newCoords[0].y>=containerCoords[0].y){
const newScale=(boundingRect.height)/activeObject.height;
activeObject.scaleY=newScale;
activeObject.top=(containerRect.top-(containerRect.height/2)+(activeObject.height*activeObject.scaleY)/2);
}
//对
角点=['tr','mr','br'];
if(包括(corners、event.transform.corner)和&newCoords[2].x