{"id":14883,"date":"2024-07-16T08:46:26","date_gmt":"2024-07-16T00:46:26","guid":{"rendered":"https:\/\/fgchen.com\/wpedu\/?p=14883"},"modified":"2026-03-30T14:30:33","modified_gmt":"2026-03-30T06:30:33","slug":"%e7%b7%9a%e4%b8%8a%e8%a1%a3%e6%9c%8d%e6%8f%9b%e8%89%b2","status":"publish","type":"post","link":"https:\/\/fgchen.com\/wpedu\/2024\/07\/%e7%b7%9a%e4%b8%8a%e8%a1%a3%e6%9c%8d%e6%8f%9b%e8%89%b2\/","title":{"rendered":"\u7dda\u4e0a\u8863\u670d\u63db\u8272"},"content":{"rendered":"<p>\u7dda\u4e0a\u8863\u670d\u63db\u8272\u7684\u7db2\u9801\uff0c\u4f7f\u7528HTML\u3001CSS\u548cJavaScript\u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u793a\u7bc4\u5982\u4f55\u505a\u5230\u9019\u4e00\u9ede\uff1a<\/p>\n<ol>\n<li><strong>HTML\u90e8\u5206<\/strong>\uff1a\u7528\u65bc\u986f\u793a\u8863\u670d\u548c\u9078\u64c7\u984f\u8272\u7684\u754c\u9762\u3002<\/li>\n<li><strong>CSS\u90e8\u5206<\/strong>\uff1a\u7528\u65bc\u8a2d\u7f6e\u7db2\u9801\u7684\u57fa\u672c\u6a23\u5f0f\u3002<\/li>\n<li><strong>JavaScript\u90e8\u5206<\/strong>\uff1a\u7528\u65bc\u8655\u7406\u984f\u8272\u5207\u63db\u7684\u908f\u8f2f\u3002<\/li>\n<\/ol>\n<h3>1. HTML<\/h3>\n<pre><code class=\"language-html\">&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n    &lt;title&gt;Online Clothes Color Changer&lt;\/title&gt;\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;div class=&quot;container&quot;&gt;\n        &lt;h1&gt;Online Clothes Color Changer&lt;\/h1&gt;\n        &lt;div class=&quot;image-container&quot;&gt;\n            &lt;img id=&quot;clothesImage&quot; src=&quot;shirt.png&quot; alt=&quot;Shirt&quot;&gt;\n        &lt;\/div&gt;\n        &lt;div class=&quot;color-picker&quot;&gt;\n            &lt;label for=&quot;colorInput&quot;&gt;Choose a color:&lt;\/label&gt;\n            &lt;input type=&quot;color&quot; id=&quot;colorInput&quot; name=&quot;colorInput&quot;&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n    &lt;script src=&quot;script.js&quot;&gt;&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h3>2. CSS<\/h3>\n<pre><code class=\"language-css\">\/* styles.css *\/\nbody {\n    font-family: Arial, sans-serif;\n    display: flex;\n    justify-content: center;\n    align-items: center;\n    height: 100vh;\n    background-color: #f0f0f0;\n    margin: 0;\n}\n\n.container {\n    text-align: center;\n}\n\n.image-container {\n    margin-bottom: 20px;\n}\n\n#clothesImage {\n    width: 300px;\n    height: auto;\n}\n\n.color-picker {\n    margin-top: 20px;\n}<\/code><\/pre>\n<h3>3. JavaScript<\/h3>\n<pre><code class=\"language-javascript\">\/\/ script.js\ndocument.addEventListener(&quot;DOMContentLoaded&quot;, function() {\n    const colorInput = document.getElementById(&#039;colorInput&#039;);\n    const clothesImage = document.getElementById(&#039;clothesImage&#039;);\n\n    colorInput.addEventListener(&#039;input&#039;, function() {\n        const color = colorInput.value;\n        clothesImage.style.filter = `hue-rotate(${getHueRotation(color)}deg)`;\n    });\n\n    function getHueRotation(color) {\n        \/\/ Extract the red, green, and blue components of the color\n        const r = parseInt(color.slice(1, 3), 16);\n        const g = parseInt(color.slice(3, 5), 16);\n        const b = parseInt(color.slice(5, 7), 16);\n\n        \/\/ Convert RGB to HSL\n        let max = Math.max(r, g, b), min = Math.min(r, g, b);\n        let h, s, l = (max + min) \/ 2;\n\n        if (max === min) {\n            h = s = 0; \/\/ achromatic\n        } else {\n            const d = max - min;\n            s = l &gt; 0.5 ? d \/ (2 - max - min) : d \/ (max + min);\n            switch (max) {\n                case r: h = (g - b) \/ d + (g &lt; b ? 6 : 0); break;\n                case g: h = (b - r) \/ d + 2; break;\n                case b: h = (r - g) \/ d + 4; break;\n            }\n            h \/= 6;\n        }\n\n        return h * 360;\n    }\n});<\/code><\/pre>\n<h3>4. \u5716\u50cf\u8655\u7406<\/h3>\n<p>\u4f60\u9700\u8981\u4e00\u500b\u900f\u660e\u80cc\u666f\u7684\u8863\u670d\u5716\u50cf\uff0c\u4f8b\u5982 <code>shirt.png<\/code>\u3002\u9019\u500b\u5716\u50cf\u61c9\u8a72\u662f\u7070\u8272\u6216\u767d\u8272\u7684\u8863\u670d\uff0c\u9019\u6a23\u53ef\u4ee5\u66f4\u597d\u5730\u5c55\u793a\u984f\u8272\u8b8a\u5316\u6548\u679c\u3002<\/p>\n<h3>\u8aaa\u660e<\/h3>\n<ol>\n<li>HTML\u6587\u4ef6\u69cb\u5efa\u57fa\u672c\u7684\u7db2\u9801\u7d50\u69cb\uff0c\u5305\u62ec\u986f\u793a\u8863\u670d\u7684\u5716\u50cf\u548c\u984f\u8272\u9078\u64c7\u5668\u3002<\/li>\n<li>CSS\u6587\u4ef6\u8a2d\u7f6e\u7db2\u9801\u7684\u57fa\u672c\u6a23\u5f0f\uff0c\u4f7f\u5176\u66f4\u7f8e\u89c0\u3002<\/li>\n<li>JavaScript\u6587\u4ef6\u5305\u542b\u908f\u8f2f\uff0c\u7528\u65bc\u8655\u7406\u984f\u8272\u9078\u64c7\u5668\u7684\u8f38\u5165\u4e26\u52d5\u614b\u6539\u8b8a\u8863\u670d\u7684\u984f\u8272\u3002\u901a\u904e\u6539\u8b8a\u5716\u50cf\u7684 <code>filter<\/code> \u5c6c\u6027\u4f86\u5be6\u73fe\u9019\u4e00\u9ede\u3002<\/li>\n<\/ol>\n<p>\u9019\u500b\u7c21\u55ae\u7684\u5be6\u73fe\u65b9\u5f0f\u5229\u7528\u4e86CSS\u7684 <code>hue-rotate<\/code> \u5c6c\u6027\u4f86\u6539\u8b8a\u5716\u50cf\u7684\u984f\u8272\u3002\u7576\u7528\u6236\u9078\u64c7\u4e0d\u540c\u7684\u984f\u8272\u6642\uff0cJavaScript\u8a08\u7b97\u8a72\u984f\u8272\u7684\u8272\u8abf\u65cb\u8f49\u89d2\u5ea6\u4e26\u61c9\u7528\u65bc\u5716\u50cf\u3002\u9019\u6a23\u4f60\u5c31\u53ef\u4ee5\u5be6\u73fe\u4e00\u500b\u7c21\u55ae\u7684\u7dda\u4e0a\u8863\u670d\u63db\u8272\u529f\u80fd\u3002\u5982\u679c\u9700\u8981\u66f4\u7cbe\u7d30\u7684\u984f\u8272\u63a7\u5236\u548c\u6548\u679c\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528Canvas API\u6216\u5176\u4ed6\u5716\u50cf\u8655\u7406\u6280\u8853\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7dda\u4e0a\u8863\u670d\u63db\u8272\u7684\u7db2\u9801\uff0c\u4f7f\u7528HTML\u3001CSS\u548cJavaScript\u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u793a\u7bc4\u5982 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":14707,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[266],"tags":[],"class_list":["post-14883","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-266"],"_links":{"self":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/14883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/comments?post=14883"}],"version-history":[{"count":1,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/14883\/revisions"}],"predecessor-version":[{"id":14884,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/14883\/revisions\/14884"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media\/14707"}],"wp:attachment":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media?parent=14883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/categories?post=14883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/tags?post=14883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}