当前位置:网站首页>Fabric.js 手动加粗文本iText
Fabric.js 手动加粗文本iText
2022-06-23 21:59:00 【InfoQ】
本文简介
Fabric.jsIText
- 全文加粗
- 只加粗选中的文字
Fabric.js全文加粗

ITextfontWeightboldfontWeightnormalcanvas.renderAll()<button onclick="bold()">加粗</button>
<canvas id="c2" width="250" height="300" style="border: 1px solid #ccc"></canvas>
<!-- 引入fabric.js -->
<script src="js/fabric.js"></script>
<script>
// 创建画布
const canvas = new fabric.Canvas('c2')
// 创建文本
const iText = new fabric.IText('hello world')
canvas.add(iText)
function bold() {
// 当前选中的元素
let activeTxt = canvas.getActiveObject()
// 只有选中文本才执行以下操作
if (activeTxt) {
activeTxt.fontWeight = 'bold' // 将字体加粗
canvas.renderAll() // 重新渲染画布
}
}
</script>
加粗选中的文字

setSelectionStyles<button onclick="bold()">加粗</button>
<canvas id="c2" width="250" height="300" style="border: 1px solid #ccc"></canvas>
<!-- 引入fabric.js -->
<script src="js/fabric.js"></script>
<script>
// 创建画布
const canvas = new fabric.Canvas('c2')
// 创建文本
const canvas = new fabric.Canvas('c2')
// 创建文本
const iText = new fabric.IText('hello world')
canvas.add(iText)
function bold() {
// 当前选中的元素
let activeTxt = canvas.getActiveObject()
if (activeTxt) {
activeTxt.setSelectionStyles({ 'fontWeight': 'bold' }) // 设置选中文字的样式
canvas.renderAll() // 重新渲染画布
}
}
</script>
仓库
- 本文代码仓库(完整版)
边栏推荐
- Understand the data consistency between MySQL and redis
- The principle of async and await
- Desai wisdom number - histogram (basic histogram): the way to celebrate father's day in 2022
- Zynq Ultrascale+ RF Data Coverter IP配置 - ADC
- Troubleshooting of undefined problems in the channel list of easynvr channel management
- 【观察】戴尔科技+英特尔傲腾技术:以“纳秒之速”领跑存储创新
- 详解四元数
- 反序列化——php反序列化
- Section 29 basic configuration case of Tianrongxin topgate firewall
- How to write and read ASM file system data
猜你喜欢

Desai wisdom number - histogram (basic histogram): the way to celebrate father's day in 2022

Ambire Guide: the arbitrum odyssey begins! Week 1 - Cross Chain Bridge

Ant won the finqa competition champion and made a breakthrough in AI technology of long text numerical reasoning

The technical design and practice of decrypting the red envelopes of Tiktok Spring Festival

ASM文件系统 数据如何写和读数据

抖音支付十万级 TPS 流量发券实践

Phpmailer sends mail PHP
Mysql中的触发器定义及语法介绍
![[technical dry goods] the technical construction route and characteristics of zero trust in ant Office](/img/d1/ce999b9f72bbb8f692c4298b4042aa.png)
[technical dry goods] the technical construction route and characteristics of zero trust in ant Office
云原生流水线工具汇总
随机推荐
Map集合的四种遍历
The principle of async and await
什么是免疫组织化学实验? 免疫组织化学实验
【观察】戴尔科技+英特尔傲腾技术:以“纳秒之速”领跑存储创新
FANUC机器人SRVO-050碰撞检测报警原因分析及处理对策(亲测可用)
Payment industry tuyere project: smart digital operation 3.0
How to set the website construction title bar drop-down
浩哥的博客之路
ASM文件系统 数据如何写和读数据
Debian change source and uninstall useless services
Common core resource objects of kubernetes
Phpmailer sends mail PHP
PHP的curl功能扩展基本用法
运维故障经历分享
How to use data warehouse to create time series
Understand the data consistency between MySQL and redis
Talk about the problems and solutions of IT enterprise fixed assets management system
Detailed usage of exists in SQL statements
《阿里云天池大赛赛题解析》——O2O优惠卷预测
SQL Server Common SQL