当前位置:网站首页>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
边栏推荐
- PHP linked list creation and traversal
- QT how to set fixed size
- Development skills of rxjs observable custom operator
- 每日学习2
- Adhere to the foundation of 20 minutes go every day II
- Generally speaking, if the error of inconsistent tab and space occurs frequently
- Teamtalk source code analysis win client
- 博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
- 字符串匹配问题
- docker mysql
猜你喜欢

什么是 eRDMA?丨科普漫画图解

C crystal report printing

Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022

How kaggle uses utility script

Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'
![[deep learning] simple implementation of neural network forward propagation](/img/a6/9b4896c62e9b77f9d528c3c9efc58f.jpg)
[deep learning] simple implementation of neural network forward propagation

当贝投影4K激光投影X3 Pro获得一致好评:万元投影仪首选

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

Everyone believes that the one-stop credit platform makes the credit scenario "useful"
![[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)
随机推荐
SystemServer进程
How many knowledge points can a callable interface have?
PyQt5_QScrollArea内容保存成图片
The evolution process of the correct implementation principle of redis distributed lock and the summary of redison's actual combat
Selenium installing selenium in pycharm
Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'
Codeforces Round #803 (Div. 2)(A~D)
Generally speaking, if the error of inconsistent tab and space occurs frequently
快解析:轻松实现共享上网
Start to write a small demo - three piece chess
Development and design of animation surrounding mall sales website based on php+mysql
PHP linked list creation and traversal
Characteristics of selenium
Some interview suggestions for Android programmers "suggestions collection"
Everyone believes that the one-stop credit platform makes the credit scenario "useful"
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
Story points vs. human days
<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
P1042 [noip2003 popularization group] Table Tennis
MQ教程 | Exchange(交换机)