当前位置:网站首页>Fabric. Keep the original level when JS element is selected
Fabric. Keep the original level when JS element is selected
2022-07-02 14:26:00 【Director of Moral Education Department】
Brief introduction
give the thumbs-up + Focus on + Collection = Learned to
<br>
I didn't know you were using Fabric.js
Did you find it when , If there are multiple elements in a canvas , And they were stacked before , When you select the underlying element , That element will jump to the top ; When you release the element , It runs back to its original level . This is a Fabric.js
Default state of .
If you don't want this to happen during operation , You want to keep the level of the element when it is selected , Then I recommend that you initialize the canvas , Set up preserveObjectStacking
by true
.
《preserveObjectStacking file 》
<br>
Next, I will illustrate the effect and usage of this attribute .
<br>
<br>
By default
By default, the selected element will run to the top , When it is released, it runs back to its original level .
<canvas id="canvasBox" width="600" height="600" style="border: 1px solid #ccc;"></canvas><!-- introduce Fabric.js --><script src="https://cdn.bootcdn.net/ajax/libs/fabric.js/521/fabric.js"></script><script> const canvas = new fabric.Canvas('canvasBox') // circular circle = new fabric.Circle({ name: 'circle', top: 60, left: 60, radius: 30, // The radius of the circle 30 fill: 'yellowgreen' }) // rectangular rect = new fabric.Rect({ name: 'rect', top: 30, // From the top of the container 60px left: 100, // To the left of the container 200px fill: 'orange', // fill a Orange width: 60, // Width 60px height: 60 // Height 60px }) // Add rectangle to canvas canvas.add(circle, rect)</script>
The above code , I created a green circle and an orange rectangle .
stay canvas.add(circle, rect)
in , Add a circle first , Add rectangle again , So the level of rectangle will be higher than that of circle .
I deliberately adjusted the position of the two figures , Let them overlap in part .
So the final result is that the circle is under the rectangle .
<br>
Fabric.js
By default , The selected element will jump to the top , So you can see the operation effect in the above figure .
<br>
<br>
Keep the same level
If you don't want to do it by default , Especially when there are many objects in the canvas , You want the object to be manipulated to remain at its original level , This operation will be more intuitive in some cases . Then you can initialize the canvas preserveObjectStacking
Set to true
// Omitted code const canvas = new fabric.Canvas('canvasBox', { // The element object remains current when it is selected z Axis , Will not jump to the top preserveObjectStacking: true // Default false})
<br>
<br>
Code warehouse
Keep the original level when the element is selected
<br>
<br>
Recommended reading
《Fabric.js Lock background image , Not affected by zooming and dragging 》
《Fabric.js How to use the brush ?》
《Fabric.js Draw ellipses freely 》
《Fabric.js How to use an eraser ( Including recovery function )》
《Fabric.js From entry to defiance 》
give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- [to be continued] [UE4 notes] l5ue4 model import
- Golang quickly generates model and queryset of database tables
- Basic knowledge of QT original code
- Convolutional neural network (Introduction)
- PHP linked list creation and traversal
- How to set QT manual layout
- 没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法
- go操作redis
- 瀏覽器驅動的下載
- MySQL 45 lecture - learning the actual battle of MySQL in Geek time 45 Lecture Notes - 05 | easy to understand index (Part 2)
猜你喜欢
测试框架TestNG的使用(二):testNG xml的使用
全屋Wi-Fi:一个谁也解决不好的痛点?
《可供方案开发》口算训练机/数学宝/儿童口算宝/智能数学宝 LCD液晶显示驱动IC-VK1622(LQFP64封装),原厂技术支持
Codeforces Round #803 (Div. 2)(A~D)
Will your sleep service dream of the extra bookinfo on the service network
你知道Oracle的数据文件大小有上限么?
Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
uniapp自动化测试学习
Fabric.js 上划线、中划线(删除线)、下划线
c# 水晶报表打印
随机推荐
In 2021, the global styrene butadiene styrene (SBS) revenue was about $3722.7 million, and it is expected to reach $5679.6 million in 2028
Solving the longest subsequence with linear DP -- three questions
Getting started with QT - making a simple calculator
万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单
Go operation redis
Error: eacces: permission denied, access to "/usr/lib/node_modules"
selenium 元素定位方法
<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
Talk about idempotent design
Chinese science and technology from the Winter Olympics (III): the awakening and evolution of digital people
Development skills of rxjs observable custom operator
STM32-DAC实验&高频DAC输出测试
How to set QT manual layout
软件测试的方法
mongodb的认识
跨服务器数据访问的创建链接服务器方法
In 2021, the global TCB adapter revenue was about $93 million, and it is expected to reach $315.5 million in 2028
Daily learning 3
删除元素(带过渡动画)
什么是 eRDMA?丨科普漫画图解