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 , circle , ellipse, straight line, polyline, polygon, path and text.
<!-- viewBox定义画布大小 width/height定义实际大小 -->
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="300" height="300" viewBox="0 0 300 300">
<!-- 直线 (x1,y1)与(x2,y2)为两点坐标 -->
<line x1="0" y1="0" x2="250" y2="30" />
<!-- 多边形 通过多个点的坐标形成封闭图形 -->
<polygon points="5,5 100,100 50,200" />
<!-- 矩形 (x,y)为左上角起始点 -->
<rect x="100" y="100" width="120" height="100" />
<!-- 圆形 (cx,cy)圆心点 r半径 -->
<circle cx="100" cy="50" r="40" stroke="black"/>
<!-- 文本 (x,y)左下角坐标 -->
<text x="0" y="20" style="font-size:16px;font-weight: bold">Try SVG</text>
</svg>
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:
Rendering:
You can also use js to control the properties of svg, control The animation process of svg is made into an icon button that can respond to clicks and other events.
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!