{"id":3317,"date":"2024-11-10T08:32:16","date_gmt":"2024-11-10T00:32:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3317\/"},"modified":"2024-11-10T08:32:16","modified_gmt":"2024-11-10T00:32:16","slug":"js%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e8%bf%87%e6%b8%a1%e5%b1%9e%e6%80%a7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3317\/","title":{"rendered":"js\u5982\u4f55\u5b9e\u73b0\u8fc7\u6e21\u5c5e\u6027"},"content":{"rendered":"<blockquote><p>\n  js \u4f7f\u7528\u8fc7\u6e21\u5c5e\u6027\u5b9e\u73b0\u8fc7\u6e21\u6548\u679c\uff1a\u7ed9\u5143\u7d20\u6dfb\u52a0 transition \u5c5e\u6027\uff0c\u6307\u5b9a\u8981\u4fee\u6539\u7684\u5c5e\u6027\u3001\u6301\u7eed\u65f6\u95f4\u3001\u5ef6\u8fdf\u548c\u7f13\u52a8\u3002\u4fee\u6539\u5c5e\u6027\u540e\uff0c\u8fc7\u6e21\u4f1a\u81ea\u52a8\u53d1\u751f\uff0c\u4f7f\u5143\u7d20\u5c5e\u6027\u4ece\u521d\u59cb\u503c\u5e73\u6ed1\u8fc7\u6e21\u5230\u65b0\u503c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110809371859163.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u5b9e\u73b0\u8fc7\u6e21\u5c5e\u6027\u63d2\u56fe\" alt=\"js\u5982\u4f55\u5b9e\u73b0\u8fc7\u6e21\u5c5e\u6027\u63d2\u56fe\" \/><\/p>\n<p><strong>JS \u5982\u4f55\u5b9e\u73b0\u8fc7\u6e21\u5c5e\u6027<\/strong><\/p>\n<p>JavaScript (JS) \u53ef\u4ee5\u4f7f\u7528 <strong>transition<\/strong> \u5c5e\u6027\u6765\u5b9e\u73b0\u5143\u7d20\u5c5e\u6027\u7684\u5e73\u6ed1\u8fc7\u6e21\u6548\u679c\u3002\u4e0b\u9762\u662f\u5982\u4f55\u5728 JS \u4e2d\u4f7f\u7528\u8fc7\u6e21\u5c5e\u6027\uff1a<\/p>\n<p><strong>1. \u4e3a\u5143\u7d20\u6dfb\u52a0 transition \u5c5e\u6027<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u4e3a\u8981\u8fdb\u884c\u8fc7\u6e21\u7684\u5143\u7d20\u6dfb\u52a0 transition \u5c5e\u6027\u3002\u8be5\u5c5e\u6027\u7684\u503c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u6307\u5b9a\u54ea\u4e9b\u5c5e\u6027\u5e94\u8be5\u5728\u8fc7\u6e21\u671f\u95f4\u88ab\u4fee\u6539\uff0c\u4ee5\u53ca\u8fc7\u6e21\u7684\u6301\u7eed\u65f6\u95f4\u3001\u5ef6\u8fdf\u65f6\u95f4\u548c\u7f13\u52a8\u51fd\u6570\u3002<\/p>\n<p>\u8bed\u6cd5\uff1a<\/p>\n<pre>element.style.transition = \"property duration timing-function delay\";<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li> <strong>property<\/strong>\uff1a\u8981\u8fdb\u884c\u8fc7\u6e21\u7684\u5c5e\u6027\uff0c\u4f8b\u5982 &#8220;opacity&#8221; \u6216 &#8220;transform&#8221;\u3002<\/li>\n<li> <strong>duration<\/strong>\uff1a\u8fc7\u6e21\u7684\u6301\u7eed\u65f6\u95f4\uff0c\u4ee5\u79d2\u4e3a\u5355\u4f4d\u3002<\/li>\n<li> <strong>timing-function<\/strong>\uff1a\u8fc7\u6e21\u7684\u7f13\u52a8\u51fd\u6570\uff0c\u4f8b\u5982 &#8220;linear&#8221; \u6216 &#8220;ease-in-out&#8221;\u3002<\/li>\n<li> <strong>delay<\/strong>\uff1a\u8fc7\u6e21\u7684\u5ef6\u8fdf\u65f6\u95f4\uff0c\u4ee5\u79d2\u4e3a\u5355\u4f4d\u3002<\/li>\n<\/ul>\n<p><strong>\u4f8b\u5982\uff1a<\/strong><\/p>\n<pre>element.style.transition = \"opacity 1s ease-in-out\";<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>2. \u4fee\u6539\u5c5e\u6027<\/strong><\/p>\n<p>\u6dfb\u52a0 transition \u5c5e\u6027\u540e\uff0c\u5373\u53ef\u4fee\u6539\u8981\u8fdb\u884c\u8fc7\u6e21\u7684\u5c5e\u6027\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u5143\u7d20\u7684\u76f8\u5e94\u6837\u5f0f\u5c5e\u6027\u6765\u5b9e\u73b0\u3002<\/p>\n<p>\u8bed\u6cd5\uff1a<\/p>\n<pre>element.style.property = newValue;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u4f8b\u5982\uff1a<\/strong><\/p>\n<pre>element.style.opacity = 0.5;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5f53\u4fee\u6539\u5c5e\u6027\u65f6\uff0c\u8fc7\u6e21\u4f1a\u81ea\u52a8\u53d1\u751f\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u8fc7\u6e21\u5c5e\u6027\u53ea\u9002\u7528\u4e8e style \u5c5e\u6027\uff0c\u4e0d\u9002\u7528\u4e8e\u5176\u4ed6 HTML \u5c5e\u6027\u3002<\/li>\n<li>\u540c\u65f6\u8bbe\u7f6e\u591a\u4e2a\u8fc7\u6e21\u5c5e\u6027\u65f6\uff0c\u4f7f\u7528\u9017\u53f7\u5206\u9694\uff0c\u4f8b\u5982\uff1aelement.style.transition = &#8220;opacity 1s ease-in-out, transform 2s ease-out&#8221;;<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u5b9e\u73b0\u8fc7\u6e21\u5c5e\u6027\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>js \u4f7f\u7528\u8fc7\u6e21\u5c5e\u6027\u5b9e\u73b0\u8fc7\u6e21\u6548\u679c\uff1a\u7ed9\u5143\u7d20\u6dfb\u52a0 transition \u5c5e\u6027\uff0c\u6307\u5b9a\u8981\u4fee\u6539\u7684\u5c5e\u6027\u3001\u6301\u7eed\u65f6\u95f4\u3001\u5ef6\u8fdf\u548c\u7f13\u52a8\u3002\u4fee\u6539\u5c5e\u6027\u540e\uff0c\u8fc7\u6e21\u4f1a\u81ea\u52a8\u53d1\u751f\uff0c\u4f7f\u5143\u7d20\u5c5e\u6027\u4ece\u521d\u59cb\u503c\u5e73\u6ed1\u8fc7\u6e21\u5230\u65b0\u503c\u3002 JS \u5982\u4f55\u5b9e\u73b0\u8fc7\u6e21\u5c5e\u6027 JavaScript (JS) \u53ef\u4ee5\u4f7f\u7528 transition \u5c5e\u6027\u6765\u5b9e\u73b0\u5143\u7d20\u5c5e\u6027\u7684\u5e73\u6ed1\u8fc7\u6e21\u6548\u679c\u3002\u4e0b\u9762\u662f\u5982\u4f55\u5728 JS \u4e2d\u4f7f\u7528\u8fc7\u6e21\u5c5e\u6027\uff1a 1. \u4e3a\u5143\u7d20\u6dfb\u52a0 transition \u5c5e\u6027 \u9996\u5148\uff0c\u4e3a\u8981\u8fdb\u884c\u8fc7\u6e21\u7684\u5143\u7d20\u6dfb\u52a0 transition \u5c5e\u6027\u3002\u8be5\u5c5e\u6027\u7684\u503c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u6307\u5b9a\u54ea\u4e9b\u5c5e\u6027\u5e94\u8be5\u5728\u8fc7\u6e21\u671f\u95f4\u88ab\u4fee\u6539\uff0c\u4ee5\u53ca\u8fc7\u6e21\u7684\u6301\u7eed\u65f6\u95f4\u3001\u5ef6\u8fdf\u65f6\u95f4\u548c\u7f13\u52a8\u51fd\u6570\u3002 \u8bed\u6cd5\uff1a element.style.transition = &#8220;property duration timing-function delay&#8221;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a property\uff1a\u8981\u8fdb\u884c\u8fc7\u6e21\u7684\u5c5e\u6027\uff0c\u4f8b\u5982 &#8220;opacity&#8221; \u6216 &#8220;transform&#8221;\u3002 duration\uff1a\u8fc7\u6e21\u7684\u6301\u7eed\u65f6\u95f4\uff0c\u4ee5\u79d2\u4e3a\u5355\u4f4d\u3002 timing-function\uff1a\u8fc7\u6e21\u7684\u7f13\u52a8\u51fd\u6570\uff0c\u4f8b\u5982 &#8220;linear&#8221; \u6216 &#8220;ease-in-out&#8221;\u3002 delay\uff1a\u8fc7\u6e21\u7684\u5ef6\u8fdf\u65f6\u95f4\uff0c\u4ee5\u79d2\u4e3a\u5355\u4f4d\u3002 \u4f8b\u5982\uff1a element.style.transition = &#8220;opacity 1s ease-in-out&#8221;; \u767b\u5f55\u540e\u590d\u5236 2. \u4fee\u6539\u5c5e\u6027 \u6dfb\u52a0 transition \u5c5e\u6027\u540e\uff0c\u5373\u53ef\u4fee\u6539\u8981\u8fdb\u884c\u8fc7\u6e21\u7684\u5c5e\u6027\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u5143\u7d20\u7684\u76f8\u5e94\u6837\u5f0f\u5c5e\u6027\u6765\u5b9e\u73b0\u3002 \u8bed\u6cd5\uff1a element.style.property = newValue; [&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-3317","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3317","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=3317"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3317\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}