fabric.js … how to center canvas

徘徊边缘 提交于 2019-12-05 20:41:25

问题


fabricjs will convert:

//  this DOM structure
<div id="wrapper">
  <canvas id="c"></canvas>
</div>

//  to this:
<div id="wrapper">
  <div class="canvas-container">
    <canvas class="upper-canvas"></canvas>
    <canvas class="lower-canvas" id="c"></canvas>
  </div>
</div>

... see this explanation

Because of the way fabric js wraps a canvas element, how do you keep a canvas horizontally centered.

here is similar question. here is a fiddle test


回答1:


apply

margin: 0 auto;

to class = canvas-container

canvas-container is automatically created by fabric.

see fiddle




回答2:


If you are using Angular, use the project's general stylesheet (instead of the component stylesheet) to provide the css rules as @dsdsdsdsd described .canvas-container {your styles..}. otherwise your styles may not apply.



来源:https://stackoverflow.com/questions/15089839/fabric-js-how-to-center-canvas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!