{"id":21022,"date":"2024-11-19T15:56:46","date_gmt":"2024-11-19T07:56:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/21022\/"},"modified":"2024-11-19T15:56:46","modified_gmt":"2024-11-19T07:56:46","slug":"webstorm%e6%80%8e%e4%b9%88%e5%86%99%e4%b8%80%e4%b8%aa%e9%87%91%e5%ad%97%e5%a1%94","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/21022\/","title":{"rendered":"webstorm\u600e\u4e48\u5199\u4e00\u4e2a\u91d1\u5b57\u5854"},"content":{"rendered":"<blockquote><p>\n  \u5728 webstorm \u4e2d\u5236\u4f5c\u91d1\u5b57\u5854\u5f62\u7684\u65b9\u6cd5\u6709\uff1a\u521b\u5efa\u4e00\u4e2a\u753b\u5e03\uff0c\u8bbe\u7f6e\u5176\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002\u83b7\u53d6\u753b\u5e03\u7684\u4e0a\u4e0b\u6587\uff0c\u8be5\u5bf9\u8c61\u63d0\u4f9b\u7ed8\u5236\u5f62\u72b6\u7684\u51fd\u6570\u3002\u4f7f\u7528\u8def\u5f84\u51fd\u6570\u7ed8\u5236\u91d1\u5b57\u5854\u7684\u56db\u6761\u8fb9\uff0c\u5e76\u586b\u5145\u5185\u4fa7\u3002\u53ef\u9009\u5730\u8c03\u6574\u7ebf\u6761\u6837\u5f0f\u548c\u586b\u5145\u989c\u8272\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/08\/2024040816332810771.jpg\" class=\"aligncenter\" title=\"webstorm\u600e\u4e48\u5199\u4e00\u4e2a\u91d1\u5b57\u5854\u63d2\u56fe\" alt=\"webstorm\u600e\u4e48\u5199\u4e00\u4e2a\u91d1\u5b57\u5854\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 WebStorm \u4e2d\u5236\u4f5c\u91d1\u5b57\u5854\u5f62<\/strong><\/p>\n<p>\u5728 WebStorm \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5236\u4f5c\u4e00\u4e2a\u91d1\u5b57\u5854\u5f62\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u4e00\u4e2a\u753b\u5e03<\/strong><\/p>\n<ul>\n<li>\u5728 WebStorm \u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 HTML \u6587\u4ef6\u3002<\/li>\n<li>\u5728 HTML \u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e00\u4e2a \u5143\u7d20\uff0c\u8bbe\u7f6e width \u548c height \u5c5e\u6027\u3002\u4f8b\u5982\uff1a <\/li>\n<\/ul>\n<pre>&lt;canvas id=\"canvas\" width=\"500\" height=\"500\"&gt;&lt;\/canvas&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u83b7\u53d6\u753b\u5e03\u4e0a\u4e0b\u6587<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 getContext() \u65b9\u6cd5\u83b7\u53d6\u753b\u5e03\u7684\u4e0a\u4e0b\u6587\u3002<\/li>\n<li>canvasContext \u5bf9\u8c61\u63d0\u4f9b\u4e86\u4e00\u7ec4\u7528\u4e8e\u7ed8\u5236\u5f62\u72b6\u7684\u51fd\u6570\u3002<\/li>\n<\/ul>\n<pre>var canvasContext = canvas.getContext('2d');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u7ed8\u5236\u91d1\u5b57\u5854<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 beginPath() \u65b9\u6cd5\u5f00\u59cb\u7ed8\u5236\u8def\u5f84\u3002<\/li>\n<li>\u4f7f\u7528 moveTo() \u65b9\u6cd5\u5c06\u8def\u5f84\u79fb\u52a8\u5230\u91d1\u5b57\u5854\u9876\u90e8\u7684\u4e2d\u5fc3\u3002<\/li>\n<li>\u4f7f\u7528 lineTo() \u65b9\u6cd5\u7ed8\u5236\u91d1\u5b57\u5854\u7684\u56db\u6761\u8fb9\u3002<\/li>\n<li>\u4f7f\u7528 closePath() \u65b9\u6cd5\u5173\u95ed\u8def\u5f84\u3002<\/li>\n<li>\u4f7f\u7528 stroke() \u65b9\u6cd5\u7ed8\u5236\u8def\u5f84\u3002<\/li>\n<\/ul>\n<pre>canvasContext.beginPath();\ncanvasContext.moveTo(250, 50);\ncanvasContext.lineTo(100, 400);\ncanvasContext.lineTo(400, 400);\ncanvasContext.lineTo(250, 50);\ncanvasContext.closePath();\ncanvasContext.stroke();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u8c03\u6574\u6837\u5f0f\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<ul>\n<li>\u53ef\u4ee5\u901a\u8fc7\u66f4\u6539 strokeStyle \u548c lineWidth \u5c5e\u6027\u6765\u8c03\u6574\u91d1\u5b57\u5854\u7684\u7ebf\u6761\u6837\u5f0f\u3002<\/li>\n<li>\u8fd8\u53ef\u4ee5\u4f7f\u7528 fillStyle \u5c5e\u6027\u586b\u5145\u91d1\u5b57\u5854\u3002<\/li>\n<\/ul>\n<pre>canvasContext.strokeStyle = \"black\";\ncanvasContext.lineWidth = 2;\ncanvasContext.fillStyle = \"yellow\";\ncanvasContext.fill();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>&lt;canvas id=\"canvas\" width=\"500\" height=\"500\"&gt;&lt;\/canvas&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>var canvasContext = canvas.getContext('2d');\n\ncanvasContext.beginPath();\ncanvasContext.moveTo(250, 50);\ncanvasContext.lineTo(100, 400);\ncanvasContext.lineTo(400, 400);\ncanvasContext.lineTo(250, 50);\ncanvasContext.closePath();\ncanvasContext.strokeStyle = \"black\";\ncanvasContext.lineWidth = 2;\ncanvasContext.fillStyle = \"yellow\";\ncanvasContext.fill();\ncanvasContext.stroke();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5199\u4e00\u4e2a\u91d1\u5b57\u5854\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>\u5728 webstorm \u4e2d\u5236\u4f5c\u91d1\u5b57\u5854\u5f62\u7684\u65b9\u6cd5\u6709\uff1a\u521b\u5efa\u4e00\u4e2a\u753b\u5e03\uff0c\u8bbe\u7f6e\u5176\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002\u83b7\u53d6\u753b\u5e03\u7684\u4e0a\u4e0b\u6587\uff0c\u8be5\u5bf9\u8c61\u63d0\u4f9b\u7ed8\u5236\u5f62\u72b6\u7684\u51fd\u6570\u3002\u4f7f\u7528\u8def\u5f84\u51fd\u6570\u7ed8\u5236\u91d1\u5b57\u5854\u7684\u56db\u6761\u8fb9\uff0c\u5e76\u586b\u5145\u5185\u4fa7\u3002\u53ef\u9009\u5730\u8c03\u6574\u7ebf\u6761\u6837\u5f0f\u548c\u586b\u5145\u989c\u8272\u3002 \u5982\u4f55\u5728 WebStorm \u4e2d\u5236\u4f5c\u91d1\u5b57\u5854\u5f62 \u5728 WebStorm \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5236\u4f5c\u4e00\u4e2a\u91d1\u5b57\u5854\u5f62\uff1a 1. \u521b\u5efa\u4e00\u4e2a\u753b\u5e03 \u5728 WebStorm \u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 HTML \u6587\u4ef6\u3002 \u5728 HTML \u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e00\u4e2a \u5143\u7d20\uff0c\u8bbe\u7f6e width \u548c height \u5c5e\u6027\u3002\u4f8b\u5982\uff1a &lt;canvas id=&#8221;canvas&#8221; width=&#8221;500&#8243; height=&#8221;500&#8243;&gt;&lt;\/canvas&gt; \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 2. \u83b7\u53d6\u753b\u5e03\u4e0a\u4e0b\u6587 \u4f7f\u7528 getContext() \u65b9\u6cd5\u83b7\u53d6\u753b\u5e03\u7684\u4e0a\u4e0b\u6587\u3002 canvasContext \u5bf9\u8c61\u63d0\u4f9b\u4e86\u4e00\u7ec4\u7528\u4e8e\u7ed8\u5236\u5f62\u72b6\u7684\u51fd\u6570\u3002 var canvasContext = canvas.getContext(&#8216;2d&#8217;); \u767b\u5f55\u540e\u590d\u5236 3. \u7ed8\u5236\u91d1\u5b57\u5854 \u4f7f\u7528 beginPath() \u65b9\u6cd5\u5f00\u59cb\u7ed8\u5236\u8def\u5f84\u3002 \u4f7f\u7528 moveTo() \u65b9\u6cd5\u5c06\u8def\u5f84\u79fb\u52a8\u5230\u91d1\u5b57\u5854\u9876\u90e8\u7684\u4e2d\u5fc3\u3002 \u4f7f\u7528 lineTo() \u65b9\u6cd5\u7ed8\u5236\u91d1\u5b57\u5854\u7684\u56db\u6761\u8fb9\u3002 \u4f7f\u7528 closePath() [&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-21022","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21022","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=21022"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21022\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=21022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=21022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=21022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}