当前位置:网站首页>Fabric. JS manual bold text iText
Fabric. JS manual bold text iText
2022-07-02 14:26:00 【Director of Moral Education Department】
Brief introduction
give the thumbs-up + Focus on + Collection = Learned to
<br>
In this paper, Fabric.js Of IText How to make users manually bold text on the canvas .
The effect is shown in the figure :

<br>
To achieve 2 Kind of operation
- Full text bold
- Only bold the selected text
<br>
If you don't know Fabric.js What's the usage? , I highly recommend that you read 《Fabric.js From entry to defiance 》 . This article can make your front-end technology light up another skill point .
<br>
<br>
Full text bold

Just put IText Of fontWeight Property set to bold You can achieve bold .
If you want to change back to the default style , Can be fontWeight Set to normal .
After modifying the text style , You need to perform canvas.renderAll() Re render the canvas contents .
<button onclick="bold()"> In bold </button><canvas id="c2" width="250" height="300" style="border: 1px solid #ccc"></canvas><!-- introduce fabric.js --><script src="js/fabric.js"></script><script> // Create a canvas const canvas = new fabric.Canvas('c2') // Create text const iText = new fabric.IText('hello world') canvas.add(iText) function bold() { // The currently selected element let activeTxt = canvas.getActiveObject() // Only the selected text does the following if (activeTxt) { activeTxt.fontWeight = 'bold' // Bold the font canvas.renderAll() // Re render the canvas } }</script><br>
<br>
Bold selected text

It can be used setSelectionStyles Set the selected text style , Pass a style object inside .
<button onclick="bold()"> In bold </button><canvas id="c2" width="250" height="300" style="border: 1px solid #ccc"></canvas><!-- introduce fabric.js --><script src="js/fabric.js"></script><script> // Create a canvas const canvas = new fabric.Canvas('c2') // Create text const canvas = new fabric.Canvas('c2') // Create text const iText = new fabric.IText('hello world') canvas.add(iText) function bold() { // The currently selected element let activeTxt = canvas.getActiveObject() if (activeTxt) { activeTxt.setSelectionStyles({ 'fontWeight': 'bold' }) // Set the style of the selected text canvas.renderAll() // Re render the canvas } }</script><br>
<br>
Warehouse
<br>
<br>
Recommended reading
| article | brief introduction |
|---|---|
| 《Fabric.js How to use an eraser ( Including recovery function )》 | Eraser needs to download a toolkit , For details, please refer to this article . |
| 《Fabric.js Basic brush usage BaseBrush》 | Basic usage of brush |
| 《Fabric.js Draw circles freely 》 | take “ Frame selection ” The action is transformed into a free drawing circle |
| 《Fabric.js 3 individual api Set canvas width and height 》 | Width and height settings are not available only during initialization , In this paper, 3 There are three ways to set the canvas width and height , Make it easier for your canvas to adapt to different usage scenarios |
| 《Fabric.js Change the picture 3 Methods ( Including changing pictures in the Group , And the existence of cache )》 | If your project needs to dynamically change the pictures on the canvas , Then I'll summarize it for you 3 Medium method |
| 《Fabric.js Righting element 4 Methods ( With transition animation )》 | One click to place the elements that have been rotated by you |
| 《Fabric.js Upload local image to canvas background 》 | In addition to setting the canvas background during initialization , I also do the function of uploading background locally , Let the canvas modify the background image at runtime |
| 《 stay Vue3 Use in Fabric.js Achieve gradient (Gradient) effect , Including radial gradient radial》 | The official introductory tutorial also has only linear gradients , So that some articles say Fabric.js Only linear gradients are supported . But in fact Radial Gradient I fully support |
| 《Fabric.js From entry to defiance 》 | Fabric.js Getting started , Can deal with simple business after learning |
| 《Fabric.js Right-click menu 》 | Fabric.js There is no right-click event yet , If you want to realize the function of right-click menu , You can directly copy the code of this article ~ |
give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- Everyone believes that the one-stop credit platform makes the credit scenario "useful"
- Use of UIC in QT
- 全屋Wi-Fi:一个谁也解决不好的痛点?
- uniapp自动化测试学习
- [Hongke technology sharing] how to test DNS server: DNS performance and response time test
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- BeanUtils -- shallow copy -- example / principle
- 卷积神经网络(入门)
- C crystal report printing
- NLA自然语言分析实现数据分析零门槛
猜你喜欢

Use of UIC in QT

PyQt5_QScrollArea内容保存成图片

由粒子加速器产生的反中子形成的白洞

There is no solution to the decryption error of the remote user 'sa' and the service master password mapped from the remote server 'to the local user' (null) /sa '
![[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)](/img/08/9f25515e600a3174340b2589c81b0e.jpg)
[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)

The most complete analysis of Flink frame window function

MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
![[deep learning] simple implementation of neural network forward propagation](/img/a6/9b4896c62e9b77f9d528c3c9efc58f.jpg)
[deep learning] simple implementation of neural network forward propagation
![[development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)](/img/e0/e9cb42f241a60995d4598ba6a1a2fe.jpg)
[development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)

BeanUtils -- shallow copy -- example / principle
随机推荐
Selenium installing selenium in pycharm
瀏覽器驅動的下載
Data consistency between redis and database
C crystal report printing
Chinese science and technology from the Winter Olympics (III): the awakening and evolution of digital people
Use of swagger
How to set QT manual layout
Simple introduction to ENSP
docker mysql
P1908 reverse sequence pair
Basic knowledge of QT original code
《可供方案开发》口算训练机/数学宝/儿童口算宝/智能数学宝 LCD液晶显示驱动IC-VK1622(LQFP64封装),原厂技术支持
SystemServer进程
Route (II)
QT how to set fixed size
Advanced usage of C language -- function pointer: callback function; Conversion table
Qt新建项目
测试框架TestNG的使用(二):testNG xml的使用
Multi rotor aircraft control using PID and LQR controllers
Design of non main lamp: how to make intelligent lighting more "intelligent"?