当前位置:网站首页>Fabric. JS 3 APIs to set canvas width and height
Fabric. JS 3 APIs to set canvas width and height
2022-07-02 05:17:00 【Director of Moral Education Department】
Brief introduction
Use Fabric.js
When creating canvas , You can configure the width and height of the canvas in the parameters .
In addition to the settings during initialization ,Fabric.js
There are other api
For later modification of canvas width and height .
This article lists Fabric.js
Of 3 individual api
Set canvas width and height .
this 3 individual api
Simple though , But it may be important in practical development . For example, monitor browser window zoom , Dynamically adjust the width and height of the canvas .
If you want to get started Fabric.js
You can see 《Fabric.js From entry to expansion 》
<br>
<br>
Environmental statement
Chrome Browser version :96.0.4664.45
Fabric.js edition :4.6.0
I developed it in a native environment , It also provides a copy of Vue3
Code developed in the environment ( There is a link at the end of the article ).
<br>
<br>
Actual operation
This example uses the 3 individual api
:
canvas.setWidth
: Set the canvas widthcanvas.setHeight
: Set the canvas heightCanvas.setDimensions
: Set canvas size
<style> .btn-x { margin-bottom: 10px; } #canvasBox { border: 1px solid #ccc; }</style><div class="btn-x"> <button onclick="setWidth(200)"> Width 200px</button> <button onclick="setHeight(300)"> Height 300px</button> <button onclick="setDimensions(600, 400)"> One key setting width and height : Width 600px, Height 400px</button></div><canvas id="canvasBox" width="600" height="600"></canvas><script src="https://cdn.bootcdn.net/ajax/libs/fabric.js/460/fabric.min.js"></script><script> let canvas = null // Set the canvas width function setWidth(width) { canvas.setWidth(width) } // Set the canvas height function setHeight(height) { canvas.setHeight(height) } // One key setting width and height function setDimensions(width, height) { canvas.setDimensions({ width, height }) } window.onload = function() { // Use Elements id Create a canvas , At this point, you can box select... On the canvas canvas = new fabric.Canvas('canvasBox', { width: 100, height: 100 }) }</script>
<br>
<br>
Warehouse and recommended reading
Warehouse
<br>
Recommended reading
《Fabric.js Achieve gradient (Gradient) effect , Including radial gradient radial》
《Fabric.js Change the picture 3 Methods ( Including changing pictures in the Group , And the existence of cache )》 give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- CubeMx DMA笔记
- C# 图片显示占用问题
- 黑馬筆記---Set系列集合
- Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of impact roll 2022-2028: Research Report on technology, participants, trends, market size and share
- [quick view opencv] familiar with CV matrix operation with image splicing examples (3)
- 创新永不止步——nVisual网络可视化平台针对Excel导入的创新历程
- Domestic all Chinese automatic test software apifox
- Mapping settings in elk (8) es
- 7.1模拟赛总结
猜你喜欢
运维工作的“本手、妙手、俗手”
Fabric.js IText 上标和下标
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
Record my pytorch installation process and errors
Preparation for writing SAP ui5 applications using typescript
黑馬筆記---Set系列集合
[common error] the DDR type of FPGA device is selected incorrectly
Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced
Gee: remote sensing image composite and mosaic
随机推荐
Dark horse notes -- map set system
黑马笔记---Set系列集合
Set the default style of scroll bar Google browser
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
LS1046nfs挂载文件系统
黑馬筆記---Set系列集合
Draw a wave chart_ Digital IC
Fabric.js IText设置指定文字的颜色和背景色
画波形图_数字IC
leetcode存在重复元素go实现
Implementation of leetcode two number addition go
Using Kube bench and Kube hunter to evaluate the risk of kubernetes cluster
el-cascader回显只选中不显示的问题
[high speed bus] Introduction to jesd204b
Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share
A new attribute value must be added to the entity entity class in the code, but there is no corresponding column in the database table
Global and Chinese market of insulin pens 2022-2028: Research Report on technology, participants, trends, market size and share
Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced
The underlying principle of go map (storage and capacity expansion)
Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I