{"id":1949,"date":"2025-02-23T14:40:51","date_gmt":"2025-02-23T06:40:51","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=1949"},"modified":"2025-02-23T14:40:51","modified_gmt":"2025-02-23T06:40:51","slug":"html5-svg","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/23\/html5-svg\/","title":{"rendered":"HTML5 SVG"},"content":{"rendered":"\n<p>HTML5 \u5f15\u5165\u7684 <strong>SVG<\/strong>\uff08Scalable Vector Graphics\uff09\u662f\u4e00\u79cd\u57fa\u4e8e XML \u683c\u5f0f\u7684\u56fe\u5f62\u6807\u51c6\uff0c\u53ef\u4ee5\u5728\u7f51\u9875\u4e2d\u7ed8\u5236\u77e2\u91cf\u56fe\u5f62\u3002\u4e0e\u50cf\u7d20\u56fe\u50cf\u4e0d\u540c\uff0cSVG \u56fe\u50cf\u53ef\u4ee5\u65e0\u9650\u7f29\u653e\u800c\u4e0d\u5931\u771f\uff0c\u975e\u5e38\u9002\u7528\u4e8e\u56fe\u6807\u3001\u56fe\u8868\u3001\u52a8\u753b\u4ee5\u53ca\u4ea4\u4e92\u5f0f\u56fe\u5f62\u7684\u5c55\u793a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u57fa\u672c\u6982\u5ff5<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u77e2\u91cf\u56fe\u5f62<\/strong>\uff1a\u7531\u8def\u5f84\u3001\u7ebf\u6761\u3001\u66f2\u7ebf\u7b49\u7ec4\u6210\u7684\u56fe\u5f62\uff0c\u4e0e\u57fa\u4e8e\u50cf\u7d20\u7684\u56fe\u50cf\uff08\u5982 PNG\u3001JPEG \u7b49\uff09\u4e0d\u540c\uff0c\u77e2\u91cf\u56fe\u5f62\u80fd\u591f\u4fdd\u6301\u5728\u4efb\u4f55\u5206\u8fa8\u7387\u4e0b\u7684\u6e05\u6670\u5ea6\u3002<\/li>\n\n\n\n<li><strong>XML \u7ed3\u6784<\/strong>\uff1aSVG \u4f7f\u7528 XML \u683c\u5f0f\u5b9a\u4e49\u56fe\u5f62\uff0c\u56e0\u6b64\u53ef\u4ee5\u901a\u8fc7 DOM\uff08\u6587\u6863\u5bf9\u8c61\u6a21\u578b\uff09\u6765\u64cd\u4f5c\u56fe\u5f62\u5185\u5bb9\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>SVG \u57fa\u672c\u5143\u7d20<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong><code>&lt;svg&gt;<\/code><\/strong><\/h4>\n\n\n\n<p><code>&lt;svg&gt;<\/code> \u662f SVG \u56fe\u5f62\u7684\u5bb9\u5668\uff0c\u7528\u6765\u5b9a\u4e49\u4e00\u4e2a\u56fe\u5f62\u533a\u57df\uff0c\u901a\u5e38\u8bbe\u7f6e\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;circle cx=\"100\" cy=\"100\" r=\"80\" stroke=\"black\" stroke-width=\"4\" fill=\"yellow\" \/&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>&lt;circle><\/code><\/strong>\uff1a\u7ed8\u5236\u4e00\u4e2a\u5706\u5f62\uff0c<code>cx<\/code> \u548c <code>cy<\/code> \u662f\u5706\u5fc3\u7684\u5750\u6807\uff0c<code>r<\/code> \u662f\u534a\u5f84\uff0c<code>stroke<\/code> \u8bbe\u7f6e\u8fb9\u6846\u989c\u8272\uff0c<code>stroke-width<\/code> \u8bbe\u7f6e\u8fb9\u6846\u5bbd\u5ea6\uff0c<code>fill<\/code> \u8bbe\u7f6e\u586b\u5145\u989c\u8272\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u5e38\u7528 SVG \u56fe\u5f62\u5143\u7d20<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong><code>&lt;rect&gt;<\/code><\/strong><\/h4>\n\n\n\n<p><code>&lt;rect&gt;<\/code> \u7528\u4e8e\u7ed8\u5236\u77e9\u5f62\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;rect x=\"10\" y=\"10\" width=\"150\" height=\"100\" stroke=\"black\" stroke-width=\"5\" fill=\"green\" \/&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>x<\/code> \u548c <code>y<\/code><\/strong>\uff1a\u77e9\u5f62\u7684\u5de6\u4e0a\u89d2\u5750\u6807\u3002<\/li>\n\n\n\n<li><strong><code>width<\/code> \u548c <code>height<\/code><\/strong>\uff1a\u77e9\u5f62\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong><code>&lt;line&gt;<\/code><\/strong><\/h4>\n\n\n\n<p><code>&lt;line&gt;<\/code> \u7528\u4e8e\u7ed8\u5236\u76f4\u7ebf\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;line x1=\"10\" y1=\"10\" x2=\"190\" y2=\"190\" stroke=\"blue\" stroke-width=\"2\" \/&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>x1<\/code> \u548c <code>y1<\/code><\/strong>\uff1a\u76f4\u7ebf\u7684\u8d77\u70b9\u5750\u6807\u3002<\/li>\n\n\n\n<li><strong><code>x2<\/code> \u548c <code>y2<\/code><\/strong>\uff1a\u76f4\u7ebf\u7684\u7ec8\u70b9\u5750\u6807\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">3. <strong><code>&lt;polygon&gt;<\/code><\/strong><\/h4>\n\n\n\n<p><code>&lt;polygon&gt;<\/code> \u7528\u4e8e\u7ed8\u5236\u591a\u8fb9\u5f62\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;polygon points=\"100,10 190,190 10,190\" stroke=\"black\" stroke-width=\"3\" fill=\"red\" \/&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>points<\/code><\/strong>\uff1a\u591a\u4e2a\u5750\u6807\u70b9\uff0c\u7528\u7a7a\u683c\u5206\u5f00\uff0c\u8868\u793a\u591a\u8fb9\u5f62\u7684\u9876\u70b9\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4. <strong><code>&lt;path&gt;<\/code><\/strong><\/h4>\n\n\n\n<p><code>&lt;path&gt;<\/code> \u5143\u7d20\u7528\u4e8e\u7ed8\u5236\u4efb\u610f\u5f62\u72b6\u7684\u8def\u5f84\uff0c\u53ef\u4ee5\u7ec4\u5408\u76f4\u7ebf\u3001\u66f2\u7ebf\u3001\u5f27\u7ebf\u7b49\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;path d=\"M10 10 H 90 V 90 H 10 Z\" stroke=\"purple\" stroke-width=\"2\" fill=\"transparent\" \/&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>M<\/code><\/strong>\uff1a\u79fb\u52a8\u5230\u6307\u5b9a\u5750\u6807\u3002<\/li>\n\n\n\n<li><strong><code>H<\/code><\/strong>\uff1a\u6c34\u5e73\u76f4\u7ebf\u3002<\/li>\n\n\n\n<li><strong><code>V<\/code><\/strong>\uff1a\u5782\u76f4\u76f4\u7ebf\u3002<\/li>\n\n\n\n<li><strong><code>Z<\/code><\/strong>\uff1a\u5173\u95ed\u8def\u5f84\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>SVG \u6837\u5f0f<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>\u5185\u8054\u6837\u5f0f<\/strong><\/h4>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u76f4\u63a5\u5728 SVG \u5143\u7d20\u4e0a\u4f7f\u7528 <code>style<\/code> \u5c5e\u6027\u6765\u5b9a\u4e49\u6837\u5f0f\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;circle cx=\"100\" cy=\"100\" r=\"80\" style=\"stroke:black; stroke-width:4; fill:yellow;\" \/&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>CSS \u6837\u5f0f<\/strong><\/h4>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528\u5916\u90e8 CSS \u6837\u5f0f\u8868\u6765\u8bbe\u7f6e SVG \u7684\u6837\u5f0f\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;style&gt;\n    circle {\n        stroke: black;\n        stroke-width: 4;\n        fill: yellow;\n    }\n&lt;\/style&gt;\n&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;circle cx=\"100\" cy=\"100\" r=\"80\" \/&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>SVG \u52a8\u753b<\/strong><\/h3>\n\n\n\n<p>SVG \u5141\u8bb8\u901a\u8fc7 CSS \u6216 JavaScript \u5bf9\u56fe\u5f62\u8fdb\u884c\u52a8\u753b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>CSS \u52a8\u753b<\/strong><\/h4>\n\n\n\n<p>\u4f7f\u7528 <code>@keyframes<\/code> \u53ef\u4ee5\u5bf9 SVG \u5143\u7d20\u8fdb\u884c\u52a8\u753b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u52a8\u753b\u6548\u679c<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;circle cx=\"100\" cy=\"100\" r=\"80\" fill=\"yellow\"&gt;\n        &lt;animate attributeName=\"r\" from=\"80\" to=\"40\" dur=\"1s\" begin=\"0s\" repeatCount=\"indefinite\" \/&gt;\n    &lt;\/circle&gt;\n&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>animate<\/code><\/strong>\uff1a\u521b\u5efa\u52a8\u753b\u6548\u679c\uff0c<code>attributeName<\/code> \u5b9a\u4e49\u8981\u52a8\u753b\u5316\u7684\u5c5e\u6027\uff08\u5982 <code>r<\/code> \u4e3a\u534a\u5f84\uff09\uff0c<code>from<\/code> \u548c <code>to<\/code> \u5b9a\u4e49\u52a8\u753b\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u503c\uff0c<code>dur<\/code> \u5b9a\u4e49\u52a8\u753b\u6301\u7eed\u65f6\u95f4\uff0c<code>repeatCount<\/code> \u8bbe\u7f6e\u52a8\u753b\u7684\u91cd\u590d\u6b21\u6570\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>JavaScript \u52a8\u753b<\/strong><\/h4>\n\n\n\n<p>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 JavaScript \u64cd\u63a7 SVG \u5143\u7d20\u8fdb\u884c\u66f4\u590d\u6742\u7684\u52a8\u753b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u4f7f\u7528 JavaScript \u63a7\u5236\u52a8\u753b<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" id=\"mySVG\"&gt;\n    &lt;circle id=\"myCircle\" cx=\"100\" cy=\"100\" r=\"80\" fill=\"yellow\" \/&gt;\n&lt;\/svg&gt;\n\n&lt;script&gt;\n    var circle = document.getElementById(\"myCircle\");\n    var radius = 80;\n    setInterval(function() {\n        radius = radius === 80 ? 40 : 80;\n        circle.setAttribute(\"r\", radius);\n    }, 1000);\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>SVG \u4ea4\u4e92<\/strong><\/h3>\n\n\n\n<p>SVG \u5141\u8bb8\u901a\u8fc7 JavaScript \u4e0e\u7528\u6237\u8fdb\u884c\u4ea4\u4e92\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u6355\u6349\u9f20\u6807\u70b9\u51fb\u4e8b\u4ef6\uff0c\u5e76\u6539\u53d8\u56fe\u5f62\u7684\u5c5e\u6027\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u70b9\u51fb\u66f4\u6539\u989c\u8272<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;svg width=\"200\" height=\"200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"&gt;\n    &lt;circle cx=\"100\" cy=\"100\" r=\"80\" fill=\"yellow\" id=\"circle\" \/&gt;\n&lt;\/svg&gt;\n\n&lt;script&gt;\n    document.getElementById(\"circle\").addEventListener(\"click\", function() {\n        this.setAttribute(\"fill\", \"blue\");\n    });\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>SVG \u4f7f\u7528\u4f18\u52bf<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u65e0\u635f\u7f29\u653e<\/strong>\uff1a\u7531\u4e8e\u662f\u77e2\u91cf\u56fe\u5f62\uff0cSVG \u53ef\u4ee5\u7f29\u653e\u81f3\u4efb\u610f\u5927\u5c0f\u800c\u4e0d\u4e22\u5931\u6e05\u6670\u5ea6\uff0c\u9002\u7528\u4e8e\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u3002<\/li>\n\n\n\n<li><strong>\u53ef\u64cd\u4f5c\u6027<\/strong>\uff1aSVG \u662f XML \u683c\u5f0f\uff0c\u53ef\u4ee5\u901a\u8fc7 DOM \u64cd\u4f5c\u5176\u5185\u5bb9\uff0c\u975e\u5e38\u9002\u5408\u52a8\u6001\u4ea4\u4e92\u3002<\/li>\n\n\n\n<li><strong>SEO \u53cb\u597d<\/strong>\uff1aSVG \u6587\u4ef6\u662f\u6587\u672c\u683c\u5f0f\uff0c\u641c\u7d22\u5f15\u64ce\u53ef\u4ee5\u89e3\u6790\u5176\u4e2d\u7684\u5185\u5bb9\uff0c\u6709\u52a9\u4e8e\u63d0\u5347 SEO\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u5c0f\u7ed3<\/h3>\n\n\n\n<p>SVG \u662f HTML5 \u7684\u5f3a\u5927\u5de5\u5177\u4e4b\u4e00\uff0c\u9002\u5408\u7ed8\u5236\u9ad8\u8d28\u91cf\u3001\u53ef\u7f29\u653e\u7684\u56fe\u5f62\u3002\u5b83\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684 HTML \u6807\u7b7e\u76f4\u63a5\u5d4c\u5165\u5230\u7f51\u9875\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7 CSS \u548c JavaScript \u52a8\u753b\u548c\u4ea4\u4e92\u529f\u80fd\u589e\u5f3a\u5176\u6548\u679c\u3002\u65e0\u8bba\u662f\u9759\u6001\u56fe\u5f62\u8fd8\u662f\u52a8\u6001\u4ea4\u4e92\uff0cSVG \u90fd\u80fd\u63d0\u4f9b\u9ad8\u6548\u3001\u7cbe\u786e\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTML5 \u5f15\u5165\u7684 SVG\uff08Scalable Vector Graphics\uff09\u662f\u4e00\u79cd\u57fa\u4e8e XML \u683c\u5f0f\u7684\u56fe\u5f62\u6807 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[],"class_list":["post-1949","post","type-post","status-publish","format-standard","hentry","category-html5"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1949","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=1949"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1949\/revisions"}],"predecessor-version":[{"id":1950,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1949\/revisions\/1950"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=1949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=1949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=1949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}