{"id":27885,"date":"2024-11-24T14:40:30","date_gmt":"2024-11-24T06:40:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27885\/"},"modified":"2024-11-24T14:40:30","modified_gmt":"2024-11-24T06:40:30","slug":"%e5%a6%82%e4%bd%95%e7%94%a8-svg-%e5%ae%9e%e7%8e%b0%e4%b8%80%e4%b8%aa%e8%87%aa%e9%80%82%e5%ba%94%e6%b0%b4%e5%a1%94%e5%bd%a2%e7%8a%b6%e7%9a%84%e8%bf%9b%e5%ba%a6%e6%9d%a1%ef%bc%8c%e5%b9%b6%e6%a0%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27885\/","title":{"rendered":"\u5982\u4f55\u7528 SVG \u5b9e\u73b0\u4e00\u4e2a\u81ea\u9002\u5e94\u6c34\u5854\u5f62\u72b6\u7684\u8fdb\u5ea6\u6761\uff0c\u5e76\u6839\u636e\u8fdb\u5ea6\u503c\u52a8\u6001\u8c03\u6574\u6c34\u9762\u9ad8\u5ea6\u548c\u989c\u8272\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173132874438206.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7528 SVG \u5b9e\u73b0\u4e00\u4e2a\u81ea\u9002\u5e94\u6c34\u5854\u5f62\u72b6\u7684\u8fdb\u5ea6\u6761\uff0c\u5e76\u6839\u636e\u8fdb\u5ea6\u503c\u52a8\u6001\u8c03\u6574\u6c34\u9762\u9ad8\u5ea6\u548c\u989c\u8272\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7528 SVG \u5b9e\u73b0\u4e00\u4e2a\u81ea\u9002\u5e94\u6c34\u5854\u5f62\u72b6\u7684\u8fdb\u5ea6\u6761\uff0c\u5e76\u6839\u636e\u8fdb\u5ea6\u503c\u52a8\u6001\u8c03\u6574\u6c34\u9762\u9ad8\u5ea6\u548c\u989c\u8272\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u524d\u7aef \u4e0d\u89c4\u5219\u8fdb\u5ea6\u6761\uff0c\u6c42\u597d\u7684\u601d\u8def\uff1f<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<ul>\n<li>\u5236\u4f5c\u4e00\u4e2a\u4e0d\u89c4\u5219\u7684\u8fdb\u5ea6\u6761\uff0c\u5176\u5916\u89c2\u662f\u4e00\u4e2a\u6c34\u5854\uff0c\u6c34\u9762\u968f\u8fdb\u5ea6\u52a8\u6001\u8c03\u6574\u9ad8\u5ea6\u3002<\/li>\n<li>\u8fdb\u5ea6\u4f4e\u4e8e 20% \u65f6\u663e\u793a\u4e3a\u7ea2\u8272\uff0c\u5176\u4f59\u8fdb\u5ea6\u663e\u793a\u4e3a\u7eff\u8272\u3002<\/li>\n<li>\u6574\u4f53\u5c3a\u5bf8\u5e94\u81ea\u9002\u5e94\u7236\u5e03\u5c40\u3002<\/li>\n<\/ul>\n<p><strong>\u601d\u8def\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 SVG \u56fe\u7247\u4f5c\u4e3a\u8fdb\u5ea6\u6761\uff0c\u5229\u7528 clip-path \u8fdb\u884c\u88c1\u5207\u663e\u793a\u6c34\u9762\u4e0a\u5347\u6548\u679c\u3002<\/li>\n<li>\u6839\u636e\u8fdb\u5ea6\u503c\u52a8\u6001\u4fee\u6539 clip-path \u7684\u9ad8\u5ea6\uff0c\u5373\u53ef\u5b9e\u73b0\u6c34\u9762\u9ad8\u5ea6\u52a8\u6001\u53d8\u5316\u3002<\/li>\n<li>\u4f7f\u7528 CSS \u8bbe\u7f6e\u8fdb\u5ea6\u6761\u989c\u8272\uff0c\u6ee1\u8db3\u4f4e\u4e8e 20% \u7ea2\u8272\uff0c\u5176\u4f59\u8fdb\u5ea6\u7eff\u8272\u7684\u8981\u6c42\u3002<\/li>\n<li>\u4e3a\u4e86\u81ea\u9002\u5e94\u7236\u5e03\u5c40\uff0c\u4f7f\u7528 vw \u548c vh \u5355\u4f4d\u8fdb\u884c\u5c3a\u5bf8\u8bbe\u7f6e\u3002<\/li>\n<\/ul>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>&lt;svg class=\"progress-bar\" width=\"100vw\" height=\"100vh\" viewBox=\"0 0 120 120\"&gt;\n  &lt;defs&gt;\n    &lt;mask id=\"water-mask\"&gt;\n      &lt;rect width=\"100%\" height=\"100%\" fill=\"white\" \/&gt;\n    &lt;\/mask&gt;\n  &lt;\/defs&gt;\n  &lt;path id=\"water\" mask=\"url(#water-mask)\" d=\"M50 100...[\u6c34\u5854\u8f6e\u5ed3\u8def\u5f84]\" fill=\"blue\" \/&gt;\n&lt;\/svg&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<pre>.progress-bar {\n  position: absolute;\n  top: 0;\n  left: 0;\n  right: 0;\n  bottom: 0;\n}\n\n#water {\n  clip-path: inset(calc(100% - 20px) 0 0 0);\n  transition: clip-path 0.5s ease-in-out;\n}\n\n.progress-bar--low #water {\n  fill: red;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u8981\u5b9e\u73b0\u6c34\u5854\u8f6e\u5ed3\uff0c\u9700\u8981\u4f7f\u7528 SVG \u7f16\u8f91\u5668\u7ed8\u5236\u3002<\/li>\n<li>clip-path \u7684\u503c\u6839\u636e\u6c34\u5854\u8f6e\u5ed3\u548c desired \u8fdb\u5ea6\u503c\u8fdb\u884c\u8c03\u6574\u3002<\/li>\n<li>\u53ef\u4ee5\u901a\u8fc7 JavaScript \u52a8\u6001\u83b7\u53d6\u548c\u8bbe\u7f6e\u8fdb\u5ea6\u503c\uff0c\u63a7\u5236\u6c34\u9762\u9ad8\u5ea6\u548c\u989c\u8272\u53d8\u5316\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u7528 SVG \u5b9e\u73b0\u4e00\u4e2a\u81ea\u9002\u5e94\u6c34\u5854\u5f62\u72b6\u7684\u8fdb\u5ea6\u6761\uff0c\u5e76\u6839\u636e\u8fdb\u5ea6\u503c\u52a8\u6001\u8c03\u6574\u6c34\u9762\u9ad8\u5ea6\u548c\u989c\u8272\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u7aef \u4e0d\u89c4\u5219\u8fdb\u5ea6\u6761\uff0c\u6c42\u597d\u7684\u601d\u8def\uff1f \u95ee\u9898\uff1a \u5236\u4f5c\u4e00\u4e2a\u4e0d\u89c4\u5219\u7684\u8fdb\u5ea6\u6761\uff0c\u5176\u5916\u89c2\u662f\u4e00\u4e2a\u6c34\u5854\uff0c\u6c34\u9762\u968f\u8fdb\u5ea6\u52a8\u6001\u8c03\u6574\u9ad8\u5ea6\u3002 \u8fdb\u5ea6\u4f4e\u4e8e 20% \u65f6\u663e\u793a\u4e3a\u7ea2\u8272\uff0c\u5176\u4f59\u8fdb\u5ea6\u663e\u793a\u4e3a\u7eff\u8272\u3002 \u6574\u4f53\u5c3a\u5bf8\u5e94\u81ea\u9002\u5e94\u7236\u5e03\u5c40\u3002 \u601d\u8def\uff1a \u4f7f\u7528 SVG \u56fe\u7247\u4f5c\u4e3a\u8fdb\u5ea6\u6761\uff0c\u5229\u7528 clip-path \u8fdb\u884c\u88c1\u5207\u663e\u793a\u6c34\u9762\u4e0a\u5347\u6548\u679c\u3002 \u6839\u636e\u8fdb\u5ea6\u503c\u52a8\u6001\u4fee\u6539 clip-path \u7684\u9ad8\u5ea6\uff0c\u5373\u53ef\u5b9e\u73b0\u6c34\u9762\u9ad8\u5ea6\u52a8\u6001\u53d8\u5316\u3002 \u4f7f\u7528 CSS \u8bbe\u7f6e\u8fdb\u5ea6\u6761\u989c\u8272\uff0c\u6ee1\u8db3\u4f4e\u4e8e 20% \u7ea2\u8272\uff0c\u5176\u4f59\u8fdb\u5ea6\u7eff\u8272\u7684\u8981\u6c42\u3002 \u4e3a\u4e86\u81ea\u9002\u5e94\u7236\u5e03\u5c40\uff0c\u4f7f\u7528 vw \u548c vh \u5355\u4f4d\u8fdb\u884c\u5c3a\u5bf8\u8bbe\u7f6e\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a &lt;svg class=&#8221;progress-bar&#8221; width=&#8221;100vw&#8221; height=&#8221;100vh&#8221; viewBox=&#8221;0 0 120 120&#8243;&gt; &lt;defs&gt; &lt;mask id=&#8221;water-mask&#8221;&gt; &lt;rect width=&#8221;100%&#8221; height=&#8221;100%&#8221; fill=&#8221;white&#8221; \/&gt; &lt;\/mask&gt; &lt;\/defs&gt; &lt;path id=&#8221;water&#8221; mask=&#8221;url(#water-mask)&#8221; d=&#8221;M50 100&#8230;[\u6c34\u5854\u8f6e\u5ed3\u8def\u5f84]&#8221; fill=&#8221;blue&#8221; \/&gt; &lt;\/svg&gt; \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27885","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27885","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27885"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27885\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}