{"id":5025,"date":"2015-11-04T23:19:31","date_gmt":"2015-11-04T15:19:31","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=5025"},"modified":"2018-01-09T00:33:06","modified_gmt":"2018-01-08T16:33:06","slug":"css3-will-change-improve-paint","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2015\/11\/css3-will-change-improve-paint\/","title":{"rendered":"\u4f7f\u7528CSS3 will-change\u63d0\u9ad8\u9875\u9762\u6eda\u52a8\u3001\u52a8\u753b\u7b49\u6e32\u67d3\u6027\u80fd"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a><br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=5025\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=5025<\/a><\/p>\n<h3>\u4e00\u3001\u5148\u6765\u770b\u4e00\u4e2a\u4f8b\u5b50<\/h3>\n<p>\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\u6765\u81ea<a href=\"Fix scrolling performance with CSS will-change property\" target=\"_blank\">\u67d0\u5916\u6587<\/a>\uff0c\u6211\u8fd9\u91cc\u7b80\u5355\u8f6c\u8ff0\u4e0b\u3002<\/p>\n<p>\u89c6\u5dee\u6eda\u52a8\u73b0\u5728\u4e0d\u662f\u633a\u6d41\u884c\u7684\u561b\uff0c\u7136\u540e<a href=\"https:\/\/fourword.fourkitchens.com\/user\/13\" target=\"_blank\">Chris Ruppel<\/a>\u5f53\u5176\u4f7f\u7528<code>background-attachment: fixed<\/code>\u5b9e\u73b0\u80cc\u666f\u56fe\u7247\u4e0d\u968f\u6eda\u52a8\u6761\u6eda\u52a8\u800c\u6eda\u52a8\u6548\u679c\u7684\u65f6\u5019\uff0c\u53d1\u73b0\uff0c\u9875\u9762\u7684\u7ed8\u5236\u6027\u80fd\u6389\u5230\u4e86\u6bcf\u79d230\u5e27\uff0c\u8fd9\u79cd\u5e27\u9891\u4eba\u773c\u5df2\u7ecf\u53ef\u4ee5\u611f\u89c9\u5230\u4e00\u5b9a\u7684\u987f\u632b\u611f\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201511\/fourkitchens-frontpage-before_0_0.png\" width=\"1574\" height=\"328\" alt=\"\u6bcf\u79d230\u5e27\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u540e\u6765\uff0c\u53c2\u8003\u4e00\u4e9b\u5176\u4ed6\u540c\u4e8b\u8fd8\u662f\u540c\u884c\u7684\u5efa\u8bae\uff0c\u505a\u4e86\u4e00\u756a\u4f18\u5316\uff0c\u7136\u540e\uff0c\u9875\u9762\u7684\u6e32\u67d3\u6027\u80fd\u2014\u2014<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201511\/fourkitchens-frontpage-after_0_0.png\" width=\"1517\" height=\"328\" alt=\"\u4f18\u5316\u540e\u7684\u5e27\u9891\u622a\u56fe\" class=\"alignnone\" \/><\/p>\n<p>\u8fd9\u4f18\u5316\u4e4b\u524d\u5b8c\u5168\u5c31\u662f\u4fbf\u79d8\uff0c\u5c4e\u62c9\u4e0d\u51fa\u6765\u7684\u611f\u89c9\uff1b\u800c\u4f18\u5316\u4e4b\u540e\uff0c\u5b8c\u5168\u5c31\u662f\u4e00\u6cfb\u5343\u91cc\uff0c\u88e4\u5b50\u90fd\u6765\u4e0d\u53ca\u8131\u7684\u611f\u89c9\u3002<\/p>\n<blockquote><p>\u4e00\u5144\u5f97\u4fbf\u79d8\uff0c\u5728\u5395\u6240\u91cc\u4e45\u4e45\u4e0d\u80fd\u5982\u4fbf\u3002<br \/>\n\u6b63\u5728\u4ed6\u6781\u529b\u52aa\u529b\u7684\u65f6\u5019\uff0c\u770b\u4e00\u54e5\u4eec\u98ce\u4e00\u6837\u7684\u51b2\u8fdb\u5395\u6240\uff0c\u8fdb\u4e86\u4ed6\u65c1\u8fb9\u7684\u4f4d\u7f6e\uff0c\u521a\u8fdb\u53bb\u5c31\u4f20\u6765\u4e00\u771f\u72c2\u98ce\u66b4\u96e8\uff0c\u90a3\u5144\u7fa1\u6155\u7684\u5bf9\u90a3\u54e5\u4eec\u8bf4\uff1a\u54e5\u4eec\u597d\u7fa1\u6155\u4f60\u5440\uff01<br \/>\n\u90a3\u54e5\u4eec\u8bf4\uff1a\u7fa1\u6155\u5565\uff0c\u88e4\u5b50\u8fd8\u6ca1\u8131\u5462\u3002\u3002\u3002<\/p><\/blockquote>\n<p>\u5927\u5bb6\u80af\u5b9a\u4f1a\u597d\u5947\uff0c\u8fd9\u5230\u5e95\u65bd\u4e86\u4ec0\u4e48\u9b54\u6cd5\uff0c\u53ef\u4ee5\u8ba9\u6e32\u67d3\u63d0\u5347\u5982\u6b64\u4e4b\u663e\u8457\u30023\u4e2a\u5c0ftips:<\/p>\n<ol>\n<li><code>background-attachment: fixed<\/code>\u6539\u6210\u4e86<code>position: fixed<\/code>\uff0c\u56e0\u4e3a\u524d\u9762\u8fd9\u73a9\u610f\u6eda\u52a8\u5b9e\u65f6\u8ba1\u7b97\u91cd\u7ed8\uff1b<\/li>\n<li>\u80cc\u666f\u56fe\u7247\u6240\u5728\u7684\u5143\u7d20\u66ff\u6362\u4e3a<code>::before<\/code>\u4f2a\u5143\u7d20\uff1b<\/li>\n<li>\u4f7f\u7528\u4e86CSS3 <code>will-change<\/code>\u52a0\u901f\uff1b<\/li>\n<\/ol>\n<p>\u76f8\u5173\u4ee3\u7801\u5982\u4e0b\uff08\u5047\u8bbe\u7c7b\u540d\u662f<code>front<\/code>\uff09\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.front::before {\n    content: '';\n    position: fixed; <span style=\"color:green;\">\/\/ \u4ee3\u66ffbackground-attachment<\/span>\n    width: 100%;\n    height: 100%;\n    top: 0;\n    left: 0;\n    background-color: white;\n    background: url(\/img\/front\/mm.jpg) no-repeat center center;\n    background-size: cover;\n    <span style=\"color:#cd0000;\">will-change: transform;<\/span> <span style=\"color:green;\">\/\/ \u521b\u5efa\u65b0\u7684\u6e32\u67d3\u5c42<\/span>\n    z-index: -1;\n  }<\/pre>\n<\/div>\n<p>OK, \u4e3b\u89d2\u7c89\u58a8\u767b\u573a\u4e86\uff0c\u5c31\u662f<code>will-change<\/code>, \u8fd9\u662f\u4ec0\u4e48\u9b3c\uff1f<\/p>\n<h3>\u4e8c\u3001CSS3 will-change\u7c89\u58a8\u767b\u573a<\/h3>\n<p>CSS3 <code>will-change<\/code>\u5c5e\u4e8eweb\u6807\u51c6\u5c5e\u6027\uff0c\u867d\u7136\u76ee\u524d\u8fd8\u662f\u8349\u6848\u9636\u6bb5\uff0c\u4f46\u51fa\u73b0\u5df2\u7ecf\u6709\u4e9b\u65f6\u65e5\u4e86\uff0c<a href=\"http:\/\/caniuse.com\/will-change\/embed\" rel=\"nofollow\" target=\"_blank\">\u517c\u5bb9\u6027<\/a>\u8fd9\u5757Chrome\/FireFox\/Opera\u90fd\u662f\u652f\u6301\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201801\/2018-01-09_003111.png\" width=\"559\" height=\"268\" alt=\"will-chang\u517c\u5bb9\u6027e\" class=\"alignnone\" \/><\/p>\n<p>\u8fd9\u4e2a\u5c5e\u6027\u4f5c\u7528\u5f88\u5355\u7eaf\uff0c\u5c31\u662f\u201c\u589e\u5f3a\u9875\u9762\u6e32\u67d3\u6027\u80fd\u201d\u3002\u90a3\u5b83\u662f\u5982\u4f55\u589e\u5f3a\u7684\u5462\uff1f<\/p>\n<p>\u6211\u4eec\u53ef\u80fd\u542c\u542c\u8bf4\u8fc7\uff0c3D transform\u4f1a\u542f\u7528GPU\u52a0\u901f<sup>\u2460<\/sup>\uff0c\u4f8b\u5982<code>translate3D<\/code>, <code>scaleZ<\/code>\u4e4b\u7c7b\uff0c\u4f46\u662f\u5462\uff0c\u8fd9\u4e9b\u5c5e\u6027\u4e1a\u754c\u5f80\u5f80\u79f0\u4e4b\u4e3a<code>hack<\/code>\u52a0\u901f\u6cd5\u3002\u6211\u4eec\u5b9e\u9645\u4e0a\u4e0d\u9700\u8981<code>z<\/code>\u8f74\u7684\u53d8\u5316\uff0c\u4f46\u662f\u8fd8\u662f\u5047\u6a21\u5047\u6837\u5730\u58f0\u660e\u4e86\uff0c\u6b3a\u9a97\u6d4f\u89c8\u5668\uff0c\u8fd9\u5176\u5b9e\u662f\u4e00\u79cd\u4e0d\u4eba\u9053\u7684\u505a\u6cd5\u3002<\/p>\n<blockquote><p>\u2460 GPU\u5373\u56fe\u5f62\u5904\u7406\u5668\uff0c\u662f\u4e0e\u5904\u7406\u548c\u7ed8\u5236\u56fe\u5f62\u76f8\u5173\u7684\u786c\u4ef6\u3002GPU\u662f\u4e13\u4e3a\u6267\u884c\u590d\u6742\u7684\u6570\u5b66\u548c\u51e0\u4f55\u8ba1\u7b97\u800c\u8bbe\u8ba1\u7684\uff0c\u53ef\u4ee5\u8ba9CPU\u4ece\u56fe\u5f62\u5904\u7406\u7684\u4efb\u52a1\u4e2d\u89e3\u653e\u51fa\u6765\uff0c\u4ece\u800c\u6267\u884c\u5176\u4ed6\u66f4\u591a\u7684\u7cfb\u7edf\u4efb\u52a1\uff0c\u4f8b\u5982\uff0c\u9875\u9762\u7684\u8ba1\u7b97\u4e0e\u91cd\u7ed8\u3002<\/p><\/blockquote>\n<p>\u800c<code>will-change<\/code>\u5219\u5929\u751f\u4e3a\u6b64\u8bbe\u8ba1\uff0c\u987e\u540d\u601d\u610f\u201c\u6211\u8981\u53d8\u5f62\u4e86\u201d\uff0c\u793c\u8c8c\u800c\u53cb\u597d\u3002<\/p>\n<blockquote><p>\u51e0\u4f55\u8001\u5e08\uff1a\u201c\u540c\u5b66\u4eec\u6ce8\u610f\uff0c\u6211\u8981\u5f00\u59cb\u53d8\u5f62\u4e86\u3002\u201d <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/20.gif\" align=\"absmiddle\" height=\"24\"><\/p><\/blockquote>\n<p>\u54c8\u54c8\uff0c\u522b\u7b11\u3002\u771f\u662f\u8fd9\u6837\u7684\u3002<\/p>\n<p>\u5f53\u6211\u4eec\u901a\u8fc7\u67d0\u4e9b\u884c\u4e3a\uff08\u70b9\u51fb\u3001\u79fb\u52a8\u6216\u6eda\u52a8\uff09\u89e6\u53d1\u9875\u9762\u8fdb\u884c\u5927\u9762\u79ef\u7ed8\u5236\u7684\u65f6\u5019\uff0c\u6d4f\u89c8\u5668\u5f80\u5f80\u662f\u6ca1\u6709\u51c6\u5907\u7684\uff0c\u53ea\u80fd\u88ab\u52a8\u4f7f\u7528CPU\u53bb\u8ba1\u7b97\u4e0e\u91cd\u7ed8\uff0c\u7531\u4e8e\u6ca1\u6709\u4e8b\u5148\u51c6\u5907\uff0c\u5e94\u4ed8\u6e32\u67d3\u591f\u545b\uff0c\u4e8e\u662f\u6389\u5e27\uff0c\u4e8e\u662f\u5361\u987f\u3002\u800c<code>will-change<\/code>\u5219\u662f\u771f\u6b63\u7684\u884c\u4e3a\u89e6\u53d1\u4e4b\u524d\u544a\u8bc9\u6d4f\u89c8\u5668\uff1a\u201c\u6d4f\u89c8\u5668\u540c\u5b66\uff0c\u6211\u5f85\u4f1a\u513f\u5c31\u8981\u53d8\u5f62\u4e86\uff0c\u4f60\u5fc3\u7406\u548c\u751f\u7406\u4e0a\u90fd\u51c6\u5907\u51c6\u5907\u201d\u3002\u4e8e\u662f\u4e4e\uff0c\u6d4f\u89c8\u5668\u540c\u5b66\u628aGPU\u7ed9\u62c9\u4e0a\u4e86\uff0c\u4ece\u5bb9\u5e94\u5bf9\u5373\u5c06\u5230\u6765\u7684\u53d8\u5f62\u3002<\/p>\n<p>\u8fd9\u5176\u5b9e\u5f88\u597d\u7406\u89e3\u7684\uff0c\u5bf9\u5427\uff0c\u63d0\u524d\u9884\u7ea6\u4ece\u5bb9\u4e0d\u8feb\uff1b\u7a81\u7136\u9020\u8bbf\u624b\u5fd9\u811a\u4e71\u3002<\/p>\n<p>MDN\u4e0a\u663e\u793a\u8be5\u5c5e\u6027\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre class=\"brush:css line-numbers  language-css\"><span style=\"color:green;\">\/* \u5173\u952e\u5b57\u503c *\/<\/span>\n<span class=\"token property\">will-change<\/span><span class=\"token punctuation\">:<\/span> auto<span class=\"token punctuation\">;<\/span>\n<span class=\"token property\">will-change<\/span><span class=\"token punctuation\">:<\/span> scroll-position<span class=\"token punctuation\">;<\/span>\n<span class=\"token property\">will-change<\/span><span class=\"token punctuation\">:<\/span> contents<span class=\"token punctuation\">;<\/span>\n<span class=\"token property\">will-change<\/span><span class=\"token punctuation\">:<\/span> transform<span class=\"token punctuation\">;<\/span>        <span style=\"color:green;\">\/* &lt;custom-ident&gt;\u793a\u4f8b *\/<\/span>\n<span class=\"token property\">will-change<\/span><span class=\"token punctuation\">:<\/span> opacity<span class=\"token punctuation\">;<\/span>          <span style=\"color:green;\">\/* &lt;custom-ident&gt;\u793a\u4f8b *\/<\/span>\n<span class=\"token property\">will-change<\/span><span class=\"token punctuation\">:<\/span> left, top<span class=\"token punctuation\">;<\/span>        <span style=\"color:green;\">\/* \u4e24\u4e2a&lt;animateable-feature&gt;\u793a\u4f8b *\/<\/span>\n\n<span style=\"color:green;\">\/* \u5168\u5c40\u503c *\/<\/span>\n<span class=\"token property\">will-change<\/span><span class=\"token punctuation\">:<\/span> inherit<span class=\"token punctuation\">;<\/span>\n<span class=\"token property\">will-change<\/span><span class=\"token punctuation\">:<\/span> initial<span class=\"token punctuation\">;<\/span>\n<span class=\"token property\">will-change<\/span><span class=\"token punctuation\">:<\/span> unset<span class=\"token punctuation\">;<\/span><span class=\"line-numbers-rows\"><span><\/span><span><\/span><span><\/span><span><\/span><span><\/span><span><\/span><span><\/span><span><\/span><span><\/span><span><\/span><span><\/span><span><\/span><\/span><\/pre>\n<\/div>\n<p>\u5176\u4e2d\uff1a<br \/>\n<strong>auto<\/strong><br \/>\n\u5c31\u8ddf<code>width:auto<\/code>\u4e00\u6837\uff0c\u5b9e\u9645\u4e0a\u6ca1\u4ec0\u4e48\u5375\u7528\uff0c\u6628\u5929\u561b\uff0c\u4f30\u8ba1\u5c31\u662f\u7528\u6765\u91cd\u7f6e\u5176\u4ed6\u6bd4\u8f83\u5c4c\u7684\u503c\u3002<\/p>\n<p><strong>scroll-position<\/strong><br \/>\n\u544a\u8bc9\u6d4f\u89c8\u5668\uff0c\u6211\u8981\u5f00\u59cb\u7ffb\u6eda\u4e86\u3002<\/p>\n<p><strong>contents<\/strong><br \/>\n\u544a\u8bc9\u6d4f\u89c8\u5668\uff0c\u5185\u5bb9\u8981\u52a8\u753b\u6216\u53d8\u5316\u4e86\u3002<\/p>\n<p><strong>&lt;custom-ident&gt;<\/strong><br \/>\n\u987e\u540d\u601d\u610f\uff0c<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/custom-ident\" target=\"_blank\">\u81ea\u5b9a\u4e49\u7684\u8bc6\u522b<\/a>\u3002\u975e\u89c4\u8303\u79f0\u547c\uff0c\u5e94\u8be5\u662fMDN\u81ea\u5df1\u7684\u79f0\u547c\uff0c\u4ee5\u540e\u53ef\u80fd\u4f1a\u660e\u786e\u5199\u5165\u89c4\u8303\u3002\u6bd4\u65b9\u8bf4<code>animation<\/code>\u7684\u540d\u79f0\uff0c\u8ba1\u6570\u5668<code>counter-reset<\/code>, <code>counter-increment<\/code>\u5b9a\u4e49\u7684\u540d\u79f0\u7b49\u7b49\u3002<\/p>\n<p>\u4e0a\u9762\u5c55\u793a\u4e862\u4e2a\u4f8b\u5b50\uff0c\u4e00\u4e2a\u662f<code>transform<\/code>\u4e00\u4e2a\u662f<code>opacity<\/code>\uff0c\u90fd\u662fCSS3\u52a8\u753b\u5e38\u7528\u5c5e\u6027\u3002\u5982\u679c\u7ed9\u5b9a\u7684\u5c5e\u6027\u662f\u7f29\u5199\uff0c\u5219\u6240\u6709\u7f29\u5199\u76f8\u5173\u5c5e\u6027\u53d8\u5316\u90fd\u4f1a\u89e6\u53d1\u3002\u540c\u65f6\u4e0d\u80fd\u662f\u4ee5\u4e0b\u8fd9\u4e9b\u5173\u952e\u5b57\u503c\uff1a<code>unset<\/code>, <code>initial<\/code>, <code>inherit<\/code>, <code>will-change<\/code>, <code>auto<\/code>, <code>scroll-position<\/code>, \u6216 <code>contents<\/code>.<\/p>\n<p><strong>&lt;animateable-feature&gt;<\/strong><br \/>\n\u53ef\u52a8\u753b\u7684\u4e00\u4e9b\u7279\u5f81\u503c\u3002\u6bd4\u65b9\u8bf4<code>left<\/code>, <code>top<\/code>, <code>margin<\/code>\u4e4b\u7c7b\u3002\u79fb\u52a8\u7aef\uff0c\u975e<code>transform<\/code>, <code>opacity<\/code>\u5c5e\u6027\u7684\u52a8\u753b\u6027\u80fd\u90fd\u662f\u4f4e\u4e0b\u7684\uff0c\u6240\u4ee5\u90fd\u662f\u5efa\u8bae\u907f\u514d\u4f7f\u7528<code>left<\/code>\/<code>top<\/code>\/<code>margin<\/code>\u4e4b\u6d41\u8fdb\u884c\u552f\u4e00\u7b49\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f60\u89c9\u5f97\u81ea\u5df1\u662f<code>margin<\/code>\u5c5e\u6027\u5976\u5927\u7684\uff0c\u975e\u8981\u4f7f\u7528\u4e4b\uff0c\u8bd5\u8bd5\u52a0\u4e2a<code>will-change:margin<\/code>\u8bf4\u4e0d\u5b9a\u4e5f\u4f1a\u5f88\u6d41\u7545\uff08\u79fb\u52a8\u7aef\u76ee\u524d\u652f\u6301\u8fd8\u4e0d\u662f\u5f88\u597d\uff09\u3002<\/p>\n<p>\u5c31\u76ee\u524d\u800c\u8a00\uff0c\u4f7f\u7528\u7684\u57fa\u672c\u4e0a\u90fd\u662f\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.example {\n  will-change: transform;\n}<\/pre>\n<\/div>\n<h3>\u4e09\u3001CSS3 will-change\u4f7f\u7528\u6ce8\u610f\u4e8b\u9879<\/h3>\n<p><code>will-change<\/code>\u867d\u7136\u53ef\u4ee5\u52a0\u901f\uff0c\u4f46\u662f\uff0c\u4e00\u5b9a\u4e00\u5b9a\u8981\u9002\u5ea6\u4f7f\u7528\u3002\u90a3\u79cd\u5168\u5c40\u90fd\u5f00\u542f<code>will-change<\/code>\u7b49\u5f85\u6a21\u5f0f\u7684\u505a\u6cd5\uff0c\u65e0\u7591\u662f\u6b7b\u8def\u4e00\u6761\u3002\u5c3c\u739b\uff0c\u7528\u811a\u8dbe\u5934\u60f3\u60f3\u4e5f\u77e5\u9053\uff0c\u4f60\u8ba9\u6d4f\u89c8\u5668\u5404\u4e2a\u5143\u7d20\u90fd\u968f\u65f6GPU\u6e32\u67d3\u52a0\u901f\u5f85\u547d\uff0c\u8fd8\u662f\u59a5\u59a5\u641e\u6b7b\uff01<\/p>\n<p>\u8bf4\u5230\u8fd9\u91cc\uff0c\u60f3\u5230\u4e86\u79fb\u52a8\u7aef\u7684GPU\u52a0\u901f\u3002\u5f88\u591a\u81ea\u4ee5\u4e3a\u7136\u7684\u540c\u5b66\u5199CSS3\u52a8\u753b\u7684\u65f6\u5019\uff0c\u6216\u8005\u9759\u6001\u5c5e\u6027\u7684\u65f6\u5019\uff0c\u52a8\u4e0d\u52a8\u5c31\u628a<code>translateZ<\/code>\u4e4b\u7c7bGPU hack\u5c5e\u6027\u5199\u4e0a\u3002\u540c\u5b66\u4eec\u554a\uff0cGPU\u8fd9\u73a9\u610f\u63d0\u9ad8\u9875\u9762\u6e32\u67d3\u6027\u80fd\u5b83\u662f\u6709\u4ee3\u4ef7\u7684\u5440\uff0c\u4ec0\u4e48\u4ee3\u4ef7\u5462\uff0c\u5c31\u662f\u624b\u673a\u7684\u7535\u91cf\u3002\u4f60\u771f\u4ee5\u4e3a\u6709\u201c\u65e2\u8981\u9a6c\u513f\u8dd1\uff0c\u53c8\u8981\u9a6c\u513f\u4e0d\u5403\u8349\u201d\u7684\u597d\u4e8b\u60c5\u554a\uff01<\/p>\n<p>\u5e73\u65f6\uff0c\u6211\u4eec\u4e00\u822c\u5730CSS\u52a8\u753b\uff0c\u5e73\u5e38\u7684\u6e32\u67d3\u5904\u7406\uff0c\u624b\u673a\u90fd\u662f\u53ef\u4ee5\u6bd4\u8f83\u6d41\u7545\u7684\u3002\u5b8c\u5168\u6ca1\u6709\u5fc5\u8981\u4ee5\u727a\u7272\u5176\u4ed6\u4e1c\u897f\u6765\u5b9e\u73b0\u3002\u624b\u673a\u4e0a\u7684\u7535\u91cf\u5f25\u8db3\u73cd\u8d35\u3002\u5982\u679c\u53d1\u73b0(\u5c24\u5176Android)\u673a\u5b50h5\u9875\u9762\u4e0d\u6d41\u7545\uff0c\u627e\u627e\u770b\u662f\u4e0d\u662f\u52a8\u753b\u5c5e\u6027\u4f7f\u7528\u95ee\u9898\uff0c\u6216\u8005\u975e\u53ef\u89c6\u52a8\u753b\u5c42\u6ca1\u9690\u85cf\u7b49\u7b49\u539f\u56e0\u3002<\/p>\n<p>\u56de\u5230<code>will-change<\/code>. \u540c\u6837\u7684\uff0c<code>will-change<\/code>\u7684\u4f7f\u7528\u4e5f\u8981\u8c28\u614e\uff0c\u9075\u5faa\u6700\u5c0f\u5316\u5f71\u54cd\u539f\u5219\uff0c\u6240\u4ee5\uff0c\u4e00\u5f00\u59cb\u7684\u4f8b\u5b50\uff0c\u624d\u4f7f\u7528\u4f2a\u5143\u7d20\u53bb\u641e\uff0c\u72ec\u7acb\u6e32\u67d3\uff08\u867d\u7136\u6211\u6ca1\u770b\u51fa\u6765\u8fd9\u4e2a\u6897\u5728\u4ec0\u4e48\u5730\u65b9\uff09\u3002<\/p>\n<p>sitePoint\u7f51\u7ad9\u4e0a\u7684<a href=\"An Introduction to the CSS will-change Property\" target=\"_blank\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u5c55\u793a\u4e86\u51e0\u4e2a\u5904\u7406\u4f8b\u5b50\uff1a<\/p>\n<p>\u4e0d\u8981\u8fd9\u6837\u76f4\u63a5\u5199\u5728\u9ed8\u8ba4\u72b6\u6001\u4e2d\uff0c\u56e0\u4e3a<code>will-change<\/code>\u4f1a\u4e00\u76f4\u6302\u7740\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.will-change {\n  will-change: transform;\n  transition: transform 0.3s;\n}\n.will-change:hover {\n  transform: scale(1.5);\n}<\/pre>\n<\/div>\n<p>\u53ef\u4ee5\u8ba9\u7236\u5143\u7d20hover\u7684\u65f6\u5019\uff0c\u58f0\u660e<code>will-change<\/code>\uff0c\u8fd9\u6837\uff0c\u79fb\u51fa\u7684\u65f6\u5019\u5c31\u4f1a\u81ea\u52a8<code>remove<\/code>\uff0c\u89e6\u53d1\u7684\u8303\u56f4\u57fa\u672c\u4e0a\u662f\u6709\u6548\u5143\u7d20\u8303\u56f4\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>.will-change-parent:hover .will-change {\n  will-change: transform;\n}\n.will-change {\n  transition: transform 0.3s;\n}\n.will-change:hover {\n  transform: scale(1.5);\n}<\/pre>\n<\/div>\n<p>\u5982\u679c\u4f7f\u7528JS\u6dfb\u52a0<code>will-change<\/code>, \u4e8b\u4ef6\u6216\u52a8\u753b\u5b8c\u6bd5\uff0c\u4e00\u5b9a\u8981\u53ca\u65f6<code>remove<\/code>. \u6bd4\u65b9\u8bf4\u70b9\u51fb\u67d0\u4e2a\u6309\u94ae\uff0c\u5176\u4ed6\u67d0\u4e2a\u5143\u7d20\u8fdb\u884c\u52a8\u753b\u3002\u70b9\u51fb\u6309\u94ae(click)\uff0c\u8981\u5148\u6309\u4e0b(mousedown)\u518d\u62ac\u8d77\u624d\u51fa\u53d1\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5<code>mousedown<\/code>\u65f6\u5019\u6253\u58f0\u62db\u547c, \u52a8\u753b\u7ed3\u675f\u81ea\u5e26\u56de\u8c03\uff0c\u4e8e\u662f\uff08\u793a\u610f\uff0c\u4e0d\u8981\u5728\u610f\u7ec6\u8282\uff09\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>dom.onmousedown = function() {\n    target.style.willChange = 'transform';\n};\ndom.onclick = function() {\n    <span style=\"color:green;\">\/\/ target\u52a8\u753b\u54d4\u54e9\u54d4\u54e9...<\/span>\n};\ntarget.onanimationend = function() {\n    <span style=\"color:green;\">\/\/ \u52a8\u753b\u7ed3\u675f\u56de\u8c03\uff0c\u79fb\u9664will-change<\/span>\n    this.style.willChange = 'auto';\n};<\/pre>\n<\/div>\n<p>\u7b49\u3002<\/p>\n<h3>\u56db\u3001\u53c2\u8003\u6587\u7ae0<\/h3>\n<ul>\n<li><a href=\"https:\/\/fourword.fourkitchens.com\/article\/fix-scrolling-performance-css-will-change-property\">Fix scrolling performance with CSS will-change property<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/will-change\">MDN:will-change<\/a><\/li>\n<li><a href=\"http:\/\/www.sitepoint.com\/introduction-css-will-change-property\/\">An Introduction to the CSS will-change Property<\/a><\/li>\n<\/ul>\n<p>\u672c\u6587\u5185\u5bb9\u5747\u5c5e\u4e8e\u5916\u6587\u6574\u7406\u6536\u96c6\uff0c\u52a0\u4e0a\u81ea\u5df1\u7406\u89e3\u4e66\u5199\u3002\u5185\u5bb9\u5e76\u672a\u4eb2\u81ea\u5b9e\u8df5\u9a8c\u8bc1\uff0c\u56e0\u6b64\uff0c\u4e0d\u80fd\u4fdd\u8bc1100%\u6b63\u786e\uff0c\u4ec5\u4f9b\u5927\u5bb6\u5b66\u4e60\u53c2\u8003\u3002<\/p>\n<p>\u5982\u679c\u6587\u4e2d\u6709\u4ec0\u4e48\u8868\u8ff0\u4e0d\u51c6\u786e\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u5927\u529b\u6307\u6b63\uff0c\u611f\u8c22\u9605\u8bfb\uff0c\u6b22\u8fce\u4ea4\u6d41\uff01<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/14.gif\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u5305\u542b\u811a\u672c\u884c\u4e3a\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=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=5025\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=5025<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS3 will-change\u5c5e\u4e8eweb\u6807\u51c6\u5c5e\u6027\uff0c\u867d\u7136\u76ee\u524d\u8fd8\u662f\u8349\u6848\u9636\u6bb5\uff0c\u4f46\u51fa\u73b0\u5df2\u7ecf\u6709\u4e9b\u65f6\u65e5\u4e86\uff0c\u517c\u5bb9\u6027\u8fd9\u5757Chrome\/FireFox\/Opera\u90fd\u662f\u652f\u6301\u7684\u3002<\/p>\n<p>\u8fd9\u4e2a\u5c5e\u6027\u4f5c\u7528\u5f88\u5355\u7eaf\uff0c\u5c31\u662f\u201c\u589e\u5f3a\u9875\u9762\u6e32\u67d3\u6027\u80fd\u201d\u3002\u90a3\u5b83\u662f\u5982\u4f55\u589e\u5f3a\u7684\u5462\uff1f<\/p>\n<p>\u672c\u6587\u90fd\u8fc7\u4e00\u4e2a\u5b9e\u4f8b\u629b\u51fawill-change\u8fd9\u4e2a\u6982\u5ff5\uff0c\u7ee7\u800c\u89e3\u91ca\u5176\u4f5c\u7528\uff0c\u5206\u6790\u5176\u8bed\u6cd5\uff0c\u63d0\u793a\u4f7f\u7528\u6ce8\u610f\u4e8b\u9879\u7b49\u3002<\/p>\n<p>\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u80fd\u591f\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\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":[177,1022,320,1021,259,321],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/5025"}],"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=5025"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/5025\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=5025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=5025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=5025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}