Home > Web Front-end > JS Tutorial > body text

Add shrink and expand animations to Polygon objects using FabricJS

WBOY
Release: 2023-09-23 22:29:02
forward
1171 people have browsed it

使用 FabricJS 向 Polygon 对象添加收缩和展开动画

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized as any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties such as angle, opacity, etc. To add shrink and expand animations we can use the scaleX and scaleY properties in conjunction with the animate method.

grammar

animate(property: String | Object, value: Number | Object):
fabric.Object | fabric.AnimationContext |
Array.
Copy after login

parameter

  • property - This property accepts a String or Object value to determine which properties we want to animate.

  • value - This property accepts a Number or Object value that determines the value property to animate.

Option key

  • scaleX: This property accepts a Number value. The assigned value determines the horizontal object scale factor. Its default value is 1.

  • scaleY: This property accepts a Number value. The assigned value determines the vertical object scale factor. Its default value is 1.

Example 1: Add shrink animation to polygons

Let's look at a code example to see how to add a shrink animation using the animate method. We pass a value of 0.5 to the scaleX and scaleY properties, which makes the polygon half its original size both horizontally and vertically.




   
   

Adding shrink animation to the polygon

You can see that shrink animation has been added to the polygon

Copy after login

Example 2: Adding an unfold animation to a polygon

In this example we will see how to add expand animation using the animate method. Since we passed a value of 1.5 to the scaleX and scaleY properties, the polygon object will be scaled 1.5 times horizontally and vertically.




   
   

Adding expand animation to the polygon

You can see that expand animation has been added to the polygon

Copy after login

in conclusion

In this tutorial, we use two simple examples to demonstrate how to add shrink and expand animations to Polygon objects using FabricJS

The above is the detailed content of Add shrink and expand animations to Polygon objects using FabricJS. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!