This chapter will introduce to you how to use SVG to create cool dynamic icons in HTML5? (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Basic graphic elements
svg has some predefined shape elements: rectangle
2. Style and effect
The style of the svg element can be written as the attribute of the tag, or it can be written in style. Here are some main style attributes:
stroke: stroke color
stroke-width: stroke width
stroke-opacity: Transparency of stroke
fill: fill color, i.e. background
fill-opacity: transparency of fill color
Transform: graphics transformation, similar to css3 transform
svg also supports many filter effects, such as gradient, shadow, blur, image mixing, etc. You don’t need to know that much. For example, if you want to draw a few colored circles, just use circle and fill.
Note: transform defaults to the upper left corner of svg as the base point, not the center of the circle or other center. The upper left corner is the origin of the svg coordinate system. To understand transform and coordinate system, you can refer to here.
3. Auxiliary elements
svg has several auxiliary elements:
The
For the transform base point problem mentioned above, you can reset the base point by nesting the
4. Realization of animation
Animation effect of svg It is implemented based on the animation tag element:
The writing method of svg is very flexible. The style can be written as a tag attribute or in style. The animation tag can be specified through xlink or written inside the animation element. The following demonstrates the xlink writing method of animateTransform:
The animation in the above example is the transition from A to B. To form a smooth cycle, at least three key points must be defined. animateTransform supports more flexible attribute settings:
values: values of multiple key points, replacing from and to, such as values="0;1;0"
keyTimes: followed by values Correspondingly, the time points of each point
calcMode: animation speed mode. discrete | linear | paced | spline
keySplines: Set the Bezier control points of motion, valid when calcMode is spline
##5. Code examples
circle draws a circle, fill coloring, wrap and position it with the g tag, transform sets the initial deformation, and animateTransform sets the animation. Now look at the code, I believe you will no longer be confused:The above is the detailed content of How to make cool dynamic icons with SVG? (code example). For more information, please follow other related articles on the PHP Chinese website!