{"id":11969,"date":"2025-12-12T19:15:50","date_gmt":"2025-12-12T11:15:50","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=11969"},"modified":"2025-12-12T19:15:50","modified_gmt":"2025-12-12T11:15:50","slug":"css-progress-function","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2025\/12\/css-progress-function\/","title":{"rendered":"CSS progress()\u51fd\u6570\u7b80\u4ecb"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=11969\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=11969<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u8981\u4fdd\u7559\u539f\u4f5c\u8005\u3001\u51fa\u5904\u4ee5\u53ca\u6587\u4e2d\u94fe\u63a5\uff0cAI\u6293\u53d6\u4fdd\u7559\u539f\u6587\u5730\u5740\uff0c\u4efb\u4f55\u7f51\u7ad9\u5747\u53ef\u6458\u8981\u805a\u5408\uff0c\u5546\u7528\u8bf7\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<h3>\u4e00\u3001progress()\u51fd\u6570\u8bed\u6cd5<\/h3>\n<p>\u6700\u8fd1CSS\u53c8\u51fa\u4e86\u4e2a\u65b0\u7684\u51fd\u6570\uff0c\u540d\u53eb<code>progress()<\/code>\uff0c\u8fd4\u56de<code>0-1<\/code>\u7684\u8fdb\u5ea6\u503c\uff0c\u6211\u7814\u7a76\u4e86\u4e0b\uff0c\u8fd9\u4e2a\u51fd\u6570\u8fd8\u662f\u6709\u4e00\u5b9a\u7684\u5b9e\u7528\u6027\u7684\u3002<\/p>\n<p>\u6211\u4eec\u5148\u770b\u4e0b\u4ed6\u7684\u8bed\u6cd5\uff1a<\/p>\n<pre>progress(&lt;value&gt;, &lt;start&gt;, &lt;end&gt;)<\/pre>\n<p>\u8fd9\u4e2a\u51fd\u6570\u652f\u63013\u4e2a\u53c2\u6570\uff0c\u5206\u522b\u662f\uff1a<\/p>\n<dl>\n<dt><strong>value<\/strong><\/dt>\n<dd>\u5f53\u524d\u8fdb\u5ea6\u503c<\/dd>\n<dt><strong>start<\/strong><\/dt>\n<dd>\u8303\u56f4\u8d77\u59cb\u503c<\/dd>\n<dt><strong>end<\/strong><\/dt>\n<dd>\u8303\u56f4\u7ed3\u675f\u503c<\/dd>\n<\/dl>\n<p>\u56e0\u6b64\uff1a<\/p>\n<ul>\n<li><code>progress(300, 0, 1000)<\/code>\u7684\u8fd4\u56de\u503c\u5c31\u662f<code>0.3<\/code>\uff1b<\/li>\n<li><code>progress(50px, 0px, 100px)<\/code>\u7684\u8fd4\u56de\u503c\u5c31\u662f<code>0.5<\/code>\uff1b<\/li>\n<li><code>progress(50%, 30%, 80%)<\/code>\u7684\u8fd4\u56de\u503c\u5c31\u662f\u2026\u2026\u8fd9\u4e2a\u8981\u8ba1\u7b97\u4e0b\uff1a<code>(50% - 30%) \/ 80%<\/code>\uff0c\u7ed3\u679c\u662f<code>0.25<\/code>\u3002<\/li>\n<\/ul>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c<code>progress()<\/code>\u7684\u5404\u4e2a\u53c2\u6570\u7684\u8ba1\u7b97\u503c\u7c7b\u578b\u9700\u8981\u4e00\u81f4\uff0c\u5982\u679c\u4e00\u4e2a\u662f\u65f6\u95f4\u503c\uff0c\u4e00\u4e2a\u662f\u957f\u5ea6\u503c\uff0c\u6216\u8005\u4e00\u4e2a\u662f\u6570\u503c\uff0c\u4e00\u4e2a\u662f\u5355\u4f4d\u503c\uff0c\u662f\u4e0d\u5408\u6cd5\u7684\uff0c\u4e0b\u9762\u8fd9\u4e24\u4e2a<code>progress()<\/code>\u8bed\u53e5\u5c31\u662f\u975e\u6cd5\u7684\uff1a<\/p>\n<pre style=\"background-color:#ffe0e5\">progress(3s, 0px, 100px)\r\nprogress(3em, 0, 100)<\/pre>\n<h3>\u4e8c\u3001progress()\u573a\u666f\u5e94\u7528<\/h3>\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c<code>progress()<\/code>\u51fd\u6570\u90fd\u662f\u4e0eCSS\u53d8\u91cf\uff0c\u6216\u8005\u662fCSS\u76f8\u5bf9\u5355\u4f4d\u7ed3\u5408\u4f7f\u7528\u7684\uff0c\u56e0\u4e3a\u53ea\u6709\u6b64\u65f6\uff0c\u5176\u8fd4\u56de\u503c\u624d\u662f\u52a8\u6001\u7684\uff0c\u624d\u6709\u4f7f\u7528\u7684\u610f\u4e49\uff0c\u5426\u5219\uff0c\u7c7b\u4f3c<code>progress(300, 0, 1000)<\/code>\u8fd9\u6837\u7684\u56fa\u5b9a\u503c\uff0c\u8fd8\u4e0d\u5982\u76f4\u63a5\u5199\u4e2a<code>0.3<\/code>\u6765\u5f97\u5feb\u6d3b\u5462\uff01<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>\/\/ CSS\u53d8\u91cf\r\nprogress(var(--container-width), 320, 1200)\r\n\/\/ \u76f8\u5bf9\u5355\u4f4d\r\nprogress(100vw, 360px, 1024px)<\/pre>\n<h4>\u6848\u4f8b<\/h4>\n<p>\u5b98\u65b9\u6848\u4f8b\u90fd\u662f\u4f7f\u7528<code>vw<\/code>\u5355\u4f4d\uff0c\u4f46\u662f\u8fd9\u4e2a\u4e0d\u592a\u65b9\u4fbf\u770b\u6587\u7ae0\u7684\u5c0f\u4f19\u4f34\u4f53\u9a8c\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u6211\u6253\u7b97\u4f7f\u7528<code>cqw<\/code>\u5355\u4f4d\u3002<\/p>\n<p>HTML\u5982\u4e0b\uff0c\u4e00\u4e2a\u5bb9\u5668\uff0c\u91cc\u9762\u6709\u4e00\u4e2a\u56fe\u7247\uff1a<\/p>\n<pre>&lt;div class=\"container\"&gt;\r\n  &lt;img src=\"mybook.jpg\" alt=\"CSS\u65b0\u4e16\u754c\"&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>\u6b64\u65f6\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528<code>progress()<\/code>\u51fd\u6570\uff0c\u8ba9\u56fe\u7247\u7684\u5bbd\u5ea6\u57fa\u4e8e\u5bb9\u5668\u5c3a\u5bf8\u52a8\u6001\u53d8\u5316\uff0cCSS\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>.container {\r\n  padding: 10px;\r\n  border: dashed gray;\r\n  container-type: inline-size;\r\n  overflow: hidden;\r\n  resize: both;\r\n  \r\n  img {\r\n    width: calc(100px + 200px * progress(80cqw, 150px, 800px));\r\n  }\r\n}<\/pre>\n<p><code>80cqw<\/code>\u8868\u793a<code>.container<\/code>\u5bb9\u5668\u5143\u7d2080%\u7684\u5bbd\u5ea6\uff0c\u7136\u540e\u8fd9\u4e2a\u5bbd\u5ea6\u8ba1\u7b97\u503c\u548c<code>150px-800px<\/code>\u8303\u56f4\u8ba1\u7b97\u8fdb\u5ea6\uff0c\u6700\u7ec8\uff0c\u56fe\u7247\u7684\u5c3a\u5bf8\u4f1a\u5728<code>100px~300px<\/code>\u53d8\u5316\u3002<\/p>\n<p>\u5b9e\u65f6\u6e32\u67d3\u6548\u679c\u5982\u4e0b\u6240\u793a\uff08\u9700\u8981Chrome 138+\uff09\uff08\u62d6\u62fd\u53f3\u4e0b\u89d2\u7684resize\u62d6\u62fd\u6761\uff09\uff1a<\/p>\n<style>.container {padding: 50px;border: dashed gray;background: #fff;container-type: inline-size;overflow: hidden;resize: both;img {width: calc(100px + 200px * progress(80cqw, 150px, 800px));}}<\/style>\n<div class=\"container\"><img decoding=\"async\" src=\"https:\/\/imgservices-1252317822.image.myqcloud.com\/coco\/s08122025\/99e58160.b1b16e.jpg\" alt=\"CSS\u65b0\u4e16\u754c\"><\/div>\n<h3>\u4e09\u3001\u517c\u5bb9\u6027\u4ee5\u53ca\u5176\u4ed6<\/h3>\n<p><code>progress()<\/code>\u4f7f\u7528\u8fd8\u633a\u7075\u6d3b\u7684\uff0c\u51fd\u6570\u53c2\u6570\u652f\u6301\u5176\u4ed6\u5e38\u89c1\u7684CSS\u8fd0\u7b97\u51fd\u6570\uff0c\u4f8b\u5982<code>calc()<\/code>\u8ba1\u7b97\uff1a<\/p>\n<pre>progress(calc(20 + 30), 0, 100)<\/pre>\n<p>\u4e5f\u53ef\u4ee5\u662f<code>calc()<\/code>\u51fd\u6570\u7684\u53c2\u6570\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>calc((progress(var(--container-width), 20%, 80%) \/ 2) + 0.5)<\/pre>\n<p>\u652f\u6301\u548c\u5176\u4ed6CSS\u51fd\u6570\uff0c\u4f8b\u5982<code>random()<\/code>\u3001<code>clamp()<\/code>\u6df7\u5408\u4f7f\u7528\u3002<\/p>\n<p>\u603b\u4e4b\uff0c\u54ea\u91cc\u9700\u8981\u4ed6\uff0c\u5c31\u4f7f\u7528\u4ed6\u3002<\/p>\n<h4>\u8fb9\u754c\u7279\u6027<\/h4>\n<p>7\u5e74\u524d\uff0c\u6211\u5199\u8fc7\u4e00\u7bc7\u6587\u7ae0\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2018\/11\/css-background-color-font-auto-match\/\">CSS\u6587\u5b57\u548c\u80cc\u666fcolor\u81ea\u52a8\u914d\u8272\u6280\u672f\u7b80\u4ecb<\/a>\u201d\uff0c\u5229\u7528\u7684\u662f<code>opacity<\/code>\u7684\u8fb9\u754c\u7279\u6027\u5b9e\u73b0\u7684\uff0c\u6bd4\u8f83\u53d6\u5de7\u3002<\/p>\n<p>\u73b0\u5728\u6709\u4e86<code>progress()<\/code>\u51fd\u6570\uff0c\u90a3\u5c31\u6bd4\u8f83\u6b63\u7edf\u4e86\uff0c\u4e5f\u66f4\u5bb9\u6613\u7406\u89e3\u4e86\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>\/\/ \u4eae\u5ea6\u5927\u4e8e0.5\uff0c\u989c\u8272\u9ed1\u8272\r\n\/\/ \u4eae\u5ea6\u5c0f\u4e8e 0.5\uff0c\u989c\u8272\u767d\u8272\r\ncolor: hsl(0, 0%, calc(100% * progress(\r\n  calc((0.5 - var(--lightness)) * infinity), 0, 1))\r\n);<\/pre>\n<p>\u8981\u662f\u5bf9<code>infinity<\/code>\u5173\u952e\u5b57\u611f\u5174\u8da3\uff0c\u53ef\u4ee5\u8bbf\u95ee\u8fd9\u7bc7\u6587\u7ae0\uff1a\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2024\/07\/css-calc-keyword-infinity-pi-e\/\">\u4e86\u89e3infinity\u3001pi\u7b49CSS calc()\u8ba1\u7b97\u5173\u952e\u5b57<\/a>\u201d<\/p>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>\u517c\u5bb9\u6027\u4e00\u822c\uff0c\u76ee\u524dChrome Only\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202512\/2025-12-12_185651.png\" width=\"573\" height=\"346\" alt=\"progress()\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u76ee\u524d\u8fd8\u53ea\u662f\u4e2a\u73a9\u5177\u3002<\/p>\n<h4>\u7ed3\u8bed<\/h4>\n<p><code>progress()<\/code> \u662f CSS \u4e2d\u7528\u4e8e\u8868\u793a\u8fdb\u5ea6\u503c\u7684\u7279\u6b8a\u51fd\u6570\uff08\u5c5e\u4e8e CSS \u6570\u503c\u51fd\u6570\u8303\u7574\uff09\uff0c\u6838\u5fc3\u4f5c\u7528\u662f\u5c06\u300c0~1 \u8303\u56f4\u5185\u7684\u8fdb\u5ea6\u503c\u300d\u6620\u5c04\u4e3a\u53ef\u89c6\u5316\u7684\u6570\u503c \/ \u989c\u8272 \/ \u5c3a\u5bf8\u7b49\uff0c\u5e38\u7528\u4e8e\u8fdb\u5ea6\u6761\u3001\u52a8\u6001\u8fc7\u6e21\u3001\u52a8\u753b\u5173\u952e\u5e27\u7b49\u573a\u666f\uff0c\u662f CSS \u539f\u751f\u5b9e\u73b0\u8fdb\u5ea6\u5173\u8054\u6837\u5f0f\u7684\u6838\u5fc3\u5de5\u5177\u3002<\/p>\n<p>\u4e0d\u8fc7\u76ee\u524d\u53d7\u5236\u4e8e\u517c\u5bb9\u6027\uff0c\u6682\u65f6\u65e0\u6cd5\u5927\u89c4\u6a21\u4f7f\u7528\uff0c\u5927\u5bb6\u4e86\u89e3\u5373\u53ef\uff01<\/p>\n<p>\u6700\u540e\uff0c\u6211\u5bb6\u767d\u8863\u6155\u6c9b\u7075\u5e0c\u671b\u5927\u5bb6\u591a\u591a\u70b9\u8d5e\u8f6c\u53d1\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202512\/2025-12-12_190135.jpeg\" width=\"167\" height=\"251\" alt=\"\u767d\u8863\u6155\u6c9b\u7075\" class=\"alignnone size-medium\" style=\"clip-path: polygon(0% 0%, 100% 0%, 100% 95%, 40% 100%, 0% 100%)\" \/><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=11969\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=11969<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202512\/2025-12-12_191333.jpeg\" width=\"160\" height=\"120\" alt=\"progress()\u5c01\u9762\u56fe\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>CSS\u53c8\u51fa\u4e86\u4e2a\u8868\u793a\u8fdb\u5ea6\u503c\u7684progress()\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u8fd8\u662f\u633a\u5b9e\u7528\u7684\uff0c\u4efb\u4f55\u4e0e\u8fdb\u5ea6\u503c\u76f8\u5173\u7684\u573a\u666f\u90fd\u662f\u4ed6\u7684\u4f7f\u7528\u573a\u666f\uff0c\u4e0d\u59a8\u8fdb\u6765\u5feb\u901f\u4e86\u89e3\u4e00\u4e0b\u5427\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[971,1865,1561,2091,780,752,1009],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/11969"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=11969"}],"version-history":[{"count":10,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/11969\/revisions"}],"predecessor-version":[{"id":12012,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/11969\/revisions\/12012"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=11969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=11969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=11969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}