当前位置:网站首页>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
边栏推荐
- Fabric.js 元素被选中时保持原有层级
- [development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)
- The evolution process of the correct implementation principle of redis distributed lock and the summary of redison's actual combat
- Federated Search: all requirements in search
- Whole house Wi Fi: a pain point that no one can solve?
- 提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
- Qt原代码基本知识
- Packet capturing tool Fiddler learning
- Adhere to the foundation of 20 minutes go every day II
- The use of TestNG, the testing framework (II): the use of TestNG XML
猜你喜欢
Simple introduction to ENSP
PHP linked list creation and traversal
当贝投影4K激光投影X3 Pro获得一致好评:万元投影仪首选
[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)
提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
SystemServer进程
没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法
Code implementation MNLM
Essential elements of science fiction 3D scenes - City
Default slot, named slot, scope slot
随机推荐
Thymeleaf dependency
Default slot, named slot, scope slot
什么是 eRDMA?丨科普漫画图解
Teamtalk source code analysis win client
What is erdma? Popular science cartoon illustration
QT - make a simple calculator - realize four operations
Selenium installing selenium in pycharm
[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)
QT new project
Systemserver process
你知道Oracle的数据文件大小有上限么?
Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
自定义事件,全局事件总线,消息订阅与发布,$nextTick
万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单
[deep learning] simple implementation of neural network forward propagation
路由(二)
每日学习2
Analysis of CPU surge in production environment service
瀏覽器驅動的下載