javascript 不能在 Fabric.js 中使用 getActiveObject()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27020560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 06:50:43  来源:igfitidea点击:

Cannot use getActiveObject() in Fabric.js

javascriptjquerycanvasfabricjs

提问by Robin Riegman

I want to check the image quality of the selected image on canvas.

我想检查画布上所选图像的图像质量。

My following code:

我的以下代码:

var canvas = $(".canvas-container").children('canvas').get(0);
//console.log(canvas.getActiveObject().get('type'));
console.log(canvas);

The getActiveObject() log gives an error: undefined is not a function.

getActiveObject() 日志给出错误:未定义不是函数。

The other log returns:

另一个日志返回:

<canvas class="lower-canvas" width="850" height="230" style="position: absolute; width: 850px; height: 230px; left: 0px; top: 0px; -webkit-user-select: none;"></canvas>

The canvas is created in another js file:

画布是在另一个 js 文件中创建的:

      //create fabric stage
        var canvas = $productStage.children('canvas').get(0);

        stage = new fabric.Canvas(canvas, {
            selection: false,
            hoverCursor: 'pointer',
            rotationCursor: 'default',
            controlsAboveOverlay: true,
            centeredScaling: true
        });

What must I change so I can use so I can use canvas.getActiveObject()?

我必须改变什么才能使用canvas.getActiveObject()?

See http://www.panel-it.eu/shop/straatnaambord-3/#for reference.

请参阅http://www.panel-it.eu/shop/straatnaambord-3/#以供参考。

Thanks in advance.

提前致谢。

回答by taveras

getActiveObject()is a method of a fabric.Canvasobject.

getActiveObject()是一个fabric.Canvas对象的方法。

With the above code, you would use stage.getActiveObject()instead of canvas.getActiveObject()

使用上面的代码,您将使用stage.getActiveObject()而不是canvas.getActiveObject()