当前位置:网站首页>Delete element (with transition animation)
Delete element (with transition animation)
2022-07-02 14:26:00 【Director of Moral Education Department】
Brief introduction
Fabric.js
Provides 2 Methods to delete objects .
One is Delete directly , Another way is With transition animation Remove elements ( Fade out animation ).
This article focuses on With transition animation How to delete elements , I'll also talk about settings The transition time is long 、 Delete the Callback function Wait for knowledge .
<br>
<br>
relevant API
Delete the element's 2 Methods :
canvas.remove(...object)
canvas.fxRemove(object, callbacksopt)
Animation duration :
canvas.FX_DURATION
<br>
canvas.remove
remove
Well understood. , It means delete . Just pass in the element object .
canvas.remove(object)
stay canvas.renderOnAddRemove
by true
Under the circumstances , Use canvas.remove
After deleting the element , The canvas will refresh automatically .
canvas.renderOnAddRemove
The default value is true
<br>
If canvas.renderOnAddRemove = false
, Use canvas.remove
after , The element is deleted , But you can still see elements on the canvas .
Manual execution is required at this time canvas.renderAll()
Or other refresh methods , The element that has just been deleted will be removed from the canvas ( Visually ) disappear .
<br>
canvas.fxRemove
fxRemove
Is a deletion method with transition animation , Objects deleted using this method fade out , Until it disappears .
This method The first parameter Is the object to delete ;
The second parameter Is a callback object , This object has 2 It's worth , Is a type function .
Namely onChange
and onComplete
.
onChange
: Called at every step of the animationonComplete
: After successful deletion, base note is called.
<br>
canvas.fxRemove(object, { onChange() { console.log(' Called at every frame of the animation ') }, onComplete() { console.log(' After successful deletion, base note is called. ') }})
<br>
canvas.FX_DURATION
canvas.FX_DURATION
You can set the duration of the transition animation .
The default value is 500, The unit is millisecond
canvas.FX_DURATION = 1500
<br>
After modification canvas.FX_DURATION
after , Try again. canvas.fxRemove
, The transition duration of deleting elements is the duration you set .
<br>
<br>
Sample code
<div class="btn-x"> <button onclick="delCircle()"> Remove elements ( Circular )</button> <button onclick="delRect()"> Delete element with animation ( square )</button></div><canvas id="canvasBox" width="600" height="600"></canvas> <script src="https://cdn.bootcdn.net/ajax/libs/fabric.js/460/fabric.min.js"></script><script> let canvas = null let circle = null let rect = null window.onload = function() { // Use Elements id Create a canvas , At this point, you can box select... On the canvas canvas = new fabric.Canvas('canvasBox', { width: 400, height: 400 }) // 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: 60, // From the top of the container 60px left: 200, // 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) } // Delete circle ( No animation ) function delCircle() { canvas.remove(circle) } // Delete rectangle ( There's animation ) function delRect() { canvas.FX_DURATION = 1500 // Animation duration , Default 500 millisecond canvas.fxRemove(rect, { onChange() { console.log(' Called at every step of the animation ') }, onComplete() { console.log(' After successful deletion, base note is called. ') } }) }</script>
<br>
<br>
Code warehouse
- Native way to achieve Remove elements ( With transition animation )
- stay Vue3 Use in Fabric Realization Remove elements ( With transition animation )
<br>
<br>
Recommended reading
《Fabric.js Upload local image to canvas background 》
《Fabric.js From entry to expansion 》
《Fabric.js Gradient effect ( Including radial gradient )》
《Fabric.js 3 individual api Set canvas width and height 》
《Fabric.js Customize the right-click menu 》
<br>
If the content of this article is helpful to you , Please also give me a compliment give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- P1042 [NOIP2003 普及组] 乒乓球
- 无主灯设计:如何让智能照明更加「智能」?
- Pychart connects to the remote server
- docker mysql
- 数据湖(十一):Iceberg表数据组织与查询
- 给Android程序员的一些面试建议「建议收藏」
- Quarkus学习四 - 项目开发到部署
- Advanced usage of C language -- function pointer: callback function; Conversion table
- 由粒子加速器产生的反中子形成的白洞
- Will your sleep service dream of the extra bookinfo on the service network
猜你喜欢
In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
抓包工具fiddler学习
Yolov3 & yolov5 output result description
The global special paper revenue in 2021 was about $27 million, and it is expected to reach $35 million in 2028. From 2022 to 2028, the CAGR was 3.8%
博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
Daily learning 2
Use bloc to build a page instance of shutter
跨服务器数据访问的创建链接服务器方法
瀏覽器驅動的下載
Design of non main lamp: how to make intelligent lighting more "intelligent"?
随机推荐
Pycharm连接远程服务器
< schematic diagram of oral arithmetic exercise machine program development> oral arithmetic exercise machine / oral arithmetic treasure / children's math treasure / children's calculator LCD LCD driv
每日学习2
Use of UIC in QT
< schéma de développement de la machine d'exercice oral > machine d'exercice oral / trésor d'exercice oral / trésor de mathématiques pour enfants / lecteur LCD de calculatrice pour enfants IC - vk1621
Quarkus学习四 - 项目开发到部署
Yyds dry goods inventory software encryption lock function
途家木鸟美团夏日折扣对垒,门槛低就一定香吗?
Using computed in uni app solves the abnormal display of data () value in tab switching
uniapp自动化测试学习
STM32-DAC实验&高频DAC输出测试
C crystal report printing
每日学习3
联合搜索:搜索中的所有需求
千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?
Whole house Wi Fi: a pain point that no one can solve?
Available solution development oral arithmetic training machine / math treasure / children's oral arithmetic treasure / intelligent math treasure LCD LCD driver ic-vk1622 (lqfp64 package), original te
Talk about idempotent design
【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
P1042 [NOIP2003 普及组] 乒乓球