当我创建Fabric.js画布对象时,Canvas会丢失样式 [英] Canvas loses style when I create Fabric.js canvas object

查看:409
本文介绍了当我创建Fabric.js画布对象时,Canvas会丢失样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Canvas对象,其顶部和左侧属性通过之前的JavaScript函数定义但是当我创建一个结构Canvas对象

I have a Canvas Object with top and left attributes defined through with a previous JavaScript function but when I create a fabric Canvas object

  var fabricCanvas= new fabric.Canvas('mycanvas');

我的HTML Canvas的顶部和左侧属性设置为0.

my HTML Canvas has top and left attributes set on 0.

我尝试在通过脚本创建Fabric Canvas对象之后设置top和left属性但是当我这样做时画布改变位置但是fabric结构函数(选择和移动函数)仍然保留在画布所在的位置之前(织物Canvas定位它的地方)!

I have tried setting the top and left attributes after the creation of fabric Canvas object through a script but when I do this the canvas changes position but the fabric function (selection and moving functions) remain where the canvas was located previously (where fabric Canvas has positioned it)!

我该怎么做才能解决这个冲突?有没有办法保持画布相等?

What can I do to resolve this conflict? Is there a way to keep equal the canvas?

推荐答案

当你用Fabric.js创建一个画布时,它将它包装在一个div中并添加第二个< canvas> (用于选择在第一个画布中渲染的对象)。 Fabric的维基页面对此进行了解释.js文件。如果要定位画布,请将CSS规则应用于父类div元素,该元素属于canvas-container类。

When you create a canvas with Fabric.js it wraps it in a div and adds a second <canvas> (used to select the objects rendered in the first canvas). This is explained in the wiki page of Fabric.js. If you want to position your canvas apply CSS rules to the parent div element which is of the class "canvas-container".

这篇关于当我创建Fabric.js画布对象时,Canvas会丢失样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆