15 Star 174 Fork 63

德育处主任/Fabric.js学习资料(中文教程)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
setWH.html 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
德育处主任 提交于 2022-01-12 23:01 +08:00 . 设置canvas宽高
<!DOCTYPE html>
<html lang="zh-cmn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>设置画布宽高</title>
<style>
.btn-x {
margin-bottom: 10px;
}
#canvasBox {
border: 1px solid #ccc;
}
</style>
</head>
<body>
<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="../../script/fabric.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>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/k21vin/fabricjs-demo.git
git@gitee.com:k21vin/fabricjs-demo.git
k21vin
fabricjs-demo
Fabric.js学习资料(中文教程)
master

搜索帮助