学习如何使用SVG创建矢量图形
SVG(可缩放矢量图形)是一种基于XML的图形格式,可以创建高质量的矢量图形:
<svg width="100" height="100">
<circle cx="50" cy="50" r="40"
stroke="black" stroke-width="3"
fill="red" />
</svg>
SVG支持多种基本图形:
<rect x="50" y="50" width="100" height="50"
fill="#e8491d" stroke="#35424a"
stroke-width="2" />
<circle cx="100" cy="75" r="40"
fill="#e8491d" stroke="#35424a"
stroke-width="2" />
<line x1="50" y1="50" x2="150" y2="100"
stroke="#e8491d" stroke-width="2" />
使用path元素创建复杂图形:
<path d="M 100 20 L 180 180 L 20 180 Z"
fill="#e8491d" stroke="#35424a"
stroke-width="2" />
SVG可以添加文本元素:
<text x="150" y="50"
text-anchor="middle"
fill="#e8491d"
font-size="24"
font-family="Arial">
Hello SVG!
</text>
SVG支持多种填充效果:
SVG支持多种动画效果:
<circle cx="100" cy="100" r="50" fill="#e8491d">
<animate attributeName="r"
values="50;60;50"
dur="2s"
repeatCount="indefinite" />
</circle>
SVG可以响应用户交互:
<circle cx="100" cy="100" r="50"
fill="#e8491d"
onmouseover="this.style.fill='#35424a'"
onmouseout="this.style.fill='#e8491d'" />