当前位置:网站首页>Fabric. Keep the original level when JS element is selected
Fabric. Keep the original level when JS element is selected
2022-06-10 17:09:00 【Director of Moral Education Division】
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 》
Next, I will illustrate the effect and usage of this attribute .
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>
Copy code 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 .
Fabric.js By default , The selected element will jump to the top , So you can see the operation effect in the above figure .
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
})
Copy code Code warehouse
边栏推荐
- Nat. Commun. | 用于加速发现抗生素抗性基因的知识整合和决策支持
- 使用KuboardSpray安装kubernetes(v1.23.1)
- Carry forward the past and forge ahead into the future, multiple residuals | densenet (II)
- NumPy 学习笔记
- 提高效率的 5 个 GoLand 快捷键,你都知道吗?
- postman切换主题
- 打造隐私计算领先方案 冲量在线数据互联平台获得鲲鹏Validated认证
- SOA architecture / test phase interface description language transformation scheme
- “禁塑令”下,中宝新材深挖可降解塑料,港交所买单吗?
- fail-fast和fail-safe
猜你喜欢

SOA架构/测试阶段接口描述语言转换方案

大山深处的孩子,正在看见更远的星空
![ASP. Net core 6 framework unveiling example demonstration [12]: advanced usage of diagnostic trace](/img/29/72c04d86e48f9fa34e5e17c44b6bd9.jpg)
ASP. Net core 6 framework unveiling example demonstration [12]: advanced usage of diagnostic trace

直播预告 | 社交新纪元,共探元宇宙社交新体验

Do you know the five GoLand shortcuts to improve efficiency?

Thread interview related questions

Detailed steps for installing redis image in docker (easy to understand, suitable for novices to get started quickly)

“禁塑令”下,中宝新材深挖可降解塑料,港交所买单吗?

Hidden Markov model and its training (1)

Mm main tables and main fields_ SAP LIUMENG_
随机推荐
一文带你了解J.U.C的FutureTask、Fork/Join框架和BlockingQueue
使用KuboardSpray安装kubernetes(v1.23.1)
ahk函数命令大全
简单实现文件上传
Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022
Nat. Commun. | 用于加速发现抗生素抗性基因的知识整合和决策支持
Fabric.js 激活输入框
postman参数化
PrimeKG : 构建知识图谱以实现精确医疗
Detailed steps for installing redis image in docker (easy to understand, suitable for novices to get started quickly)
新思科技助力以色列Visuality Systems推进安全“左移”
Download and install pycharm integrated development environment [picture]
Fabric.js 精简输出的JSON
How does Dao achieve decentralized governance?
Li Ling: in six years, how did I go from open source Xiaobai to Apache top project PMC
How to build an enterprise middle office? You need a low code platform!
【玩转华为云】鲲鹏DevKit迁移实战
Fail fast and fail safe
Tactile intelligent sharing-a133 application in laryngoscope
Fabric.js 居中元素 ️