当前位置:网站首页>Fabric.js 3个api设置画布宽高
Fabric.js 3个api设置画布宽高
2022-07-02 05:08:00 【德育处主任】
本文简介
使用 Fabric.js
创建画布时,可以在参数里配置画布的宽高。
除了初始化时设置之外,Fabric.js
还提供了其他 api
供后期修改画布宽高。
本文列举了 Fabric.js
的3个 api
设置画布宽高。
这3个 api
虽然简单,但在实际开发中可能很重要。比如监听浏览器窗口缩放,动态调整画布的宽高。
如果想入门 Fabric.js
可以看 《Fabric.js从入门到膨胀》
<br>
<br>
环境说明
Chrome浏览器版本:96.0.4664.45
Fabric.js版本:4.6.0
我是在原生环境下开发的,同时也提供了一份 Vue3
环境下开发的代码(文末有链接)。
<br>
<br>
实际操作
本例使用了3个 api
:
canvas.setWidth
:设置画布宽度canvas.setHeight
:设置画布高度Canvas.setDimensions
:设置画布大小
<style> .btn-x { margin-bottom: 10px; } #canvasBox { border: 1px solid #ccc; }</style><div class="btn-x"> <button onclick="setWidth(200)">宽度200px</button> <button onclick="setHeight(300)">高度300px</button> <button onclick="setDimensions(600, 400)">一键设置宽高:宽度600px,高度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 // 设置画布宽度 function setWidth(width) { canvas.setWidth(width) } // 设置画布高度 function setHeight(height) { canvas.setHeight(height) } // 一键设置宽高 function setDimensions(width, height) { canvas.setDimensions({ width, height }) } window.onload = function() { // 使用 元素id 创建画布,此时可以在画布上框选 canvas = new fabric.Canvas('canvasBox', { width: 100, height: 100 }) }</script>
<br>
<br>
仓库及推荐阅读
仓库
<br>
推荐阅读
边栏推荐
- 7.1模拟赛总结
- 7.1模擬賽總結
- Mathematical knowledge -- understanding and examples of fast power
- Steam教育的实际问题解决能力
- Case sharing | intelligent Western Airport
- Go implements leetcode rotation array
- 黑馬筆記---Set系列集合
- Precipitate yourself and stay up late to sort out 100 knowledge points of interface testing professional literacy
- VMware installation win10 reports an error: operating system not found
- LM09丨费雪逆变换反转网格策略
猜你喜欢
Using Kube bench and Kube hunter to evaluate the risk of kubernetes cluster
paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
el-cascader回显只选中不显示的问题
Preparation for writing SAP ui5 applications using typescript
Cubemx DMA notes
Lm09 Fisher inverse transform inversion mesh strategy
Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
Future trend of automated testing ----- self healing technology
[Yu Yue education] autumn 2021 reference materials of Tongji University
2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
随机推荐
paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
Splice characters in {{}}
js中的Map(含leetcode例题)
国产全中文-自动化测试软件Apifox
Fabric.js IText设置指定文字的颜色和背景色
7.1 Résumé du concours de simulation
Briefly introduce chown command
[Yu Yue education] autumn 2021 reference materials of Tongji University
About PROFIBUS: communication backbone network of production plant
Using Kube bench and Kube hunter to evaluate the risk of kubernetes cluster
Implementation of leetcode two number addition go
Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
el form 表单validate成功后没有执行逻辑
Summary of database problems
National all Chinese Automatic Test Software apifox
[high speed bus] Introduction to jesd204b
Future trend of automated testing ----- self healing technology
go实现leetcode旋转数组
LeetCode 241. 为运算表达式设计优先级(分治/记忆化递归/动态规划)