{"id":1836,"date":"2025-02-21T22:59:34","date_gmt":"2025-02-21T14:59:34","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=1836"},"modified":"2025-02-21T22:59:34","modified_gmt":"2025-02-21T14:59:34","slug":"css3-%e8%bf%87%e6%b8%a1","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/21\/css3-%e8%bf%87%e6%b8%a1\/","title":{"rendered":"CSS3 \u8fc7\u6e21"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">CSS3 \u8fc7\u6e21\uff08Transition\uff09\u5141\u8bb8\u4f60\u5728 CSS \u5c5e\u6027\u503c\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u6dfb\u52a0\u5e73\u6ed1\u7684\u52a8\u753b\u6548\u679c\u3002\u5b83\u4f7f\u5f97\u5143\u7d20\u4ece\u4e00\u4e2a\u72b6\u6001\u5e73\u6ed1\u8fc7\u6e21\u5230\u53e6\u4e00\u4e2a\u72b6\u6001\uff0c\u800c\u4e0d\u9700\u8981\u4f7f\u7528 JavaScript\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u57fa\u672c\u8bed\u6cd5<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fc7\u6e21\u7684\u57fa\u672c\u8bed\u6cd5\u662f\u4f7f\u7528 <code>transition<\/code> \u5c5e\u6027\uff0c\u5b83\u6709\u4ee5\u4e0b\u51e0\u4e2a\u53c2\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>transition: &lt;property&gt; &lt;duration&gt; &lt;timing-function&gt; &lt;delay&gt;;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>property<\/strong>: \u8981\u5e94\u7528\u8fc7\u6e21\u7684 CSS \u5c5e\u6027\uff0c\u53ef\u4ee5\u662f\u5355\u4e2a\u5c5e\u6027\uff0c\u4e5f\u53ef\u4ee5\u662f\u591a\u4e2a\u5c5e\u6027\uff08\u7528\u9017\u53f7\u5206\u9694\uff09\u3002<\/li>\n\n\n\n<li><strong>duration<\/strong>: \u8fc7\u6e21\u6548\u679c\u7684\u6301\u7eed\u65f6\u95f4\uff08\u4f8b\u5982\uff1a<code>1s<\/code> \u6216 <code>500ms<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>timing-function<\/strong>: \u8fc7\u6e21\u7684\u901f\u5ea6\u66f2\u7ebf\uff0c\u63a7\u5236\u52a8\u753b\u7684\u52a0\u901f\u6216\u51cf\u901f\uff08\u4f8b\u5982\uff1a<code>ease<\/code>, <code>linear<\/code>, <code>ease-in<\/code>, <code>ease-out<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>delay<\/strong>: \u8fc7\u6e21\u5f00\u59cb\u524d\u7684\u5ef6\u8fdf\u65f6\u95f4\uff08\u4f8b\u5982\uff1a<code>0s<\/code>, <code>1s<\/code>\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u7b80\u5355\u7684\u8fc7\u6e21\u793a\u4f8b<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u8fc7\u6e21\u4f8b\u5b50\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6309\u94ae\u7684\u989c\u8272\u53d8\u5316\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>button {\n  background-color: #3498db;\n  color: white;\n  padding: 10px 20px;\n  border: none;\n  cursor: pointer;\n  transition: background-color 0.3s ease;\n}\n\nbutton:hover {\n  background-color: #2ecc71; \/* \u60ac\u505c\u65f6\u80cc\u666f\u989c\u8272\u53d8\u5316 *\/\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53\u7528\u6237\u5c06\u9f20\u6807\u60ac\u505c\u5728\u6309\u94ae\u4e0a\u65f6\uff0c\u6309\u94ae\u7684\u80cc\u666f\u989c\u8272\u4f1a\u5728 0.3 \u79d2\u5185\u5e73\u6ed1\u8fc7\u6e21\uff0c\u4ece\u84dd\u8272\uff08#3498db\uff09\u53d8\u4e3a\u7eff\u8272\uff08#2ecc71\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u591a\u4e2a\u5c5e\u6027\u7684\u8fc7\u6e21<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u540c\u65f6\u4e3a\u591a\u4e2a\u5c5e\u6027\u5b9a\u4e49\u8fc7\u6e21\u6548\u679c\uff0c\u591a\u4e2a\u5c5e\u6027\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  width: 200px;\n  height: 200px;\n  background-color: #3498db;\n  transition: width 0.5s, height 0.5s, background-color 0.5s;\n}\n\ndiv:hover {\n  width: 400px;\n  height: 400px;\n  background-color: #2ecc71;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>div<\/code> \u5728\u60ac\u505c\u65f6\u4f1a\u5e73\u6ed1\u5730\u53d8\u5316\u4e3a\u66f4\u5927\u7684\u5c3a\u5bf8\uff0c\u5e76\u4e14\u80cc\u666f\u989c\u8272\u4e5f\u4f1a\u6539\u53d8\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u8fc7\u6e21\u65f6\u95f4\uff08duration\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>duration<\/code> \u63a7\u5236\u8fc7\u6e21\u52a8\u753b\u7684\u6301\u7eed\u65f6\u95f4\uff0c\u53ef\u4ee5\u4f7f\u7528\u79d2\uff08<code>s<\/code>\uff09\u6216\u6beb\u79d2\uff08<code>ms<\/code>\uff09\u4f5c\u4e3a\u5355\u4f4d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  width: 200px;\n  height: 200px;\n  background-color: #3498db;\n  transition: width 2s ease;\n}\n\ndiv:hover {\n  width: 400px;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53\u60ac\u505c\u65f6\uff0c<code>div<\/code> \u7684\u5bbd\u5ea6\u4f1a\u5728 2 \u79d2\u5185\u5e73\u6ed1\u8fc7\u6e21\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u8fc7\u6e21\u5ef6\u8fdf\uff08delay\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u8fd8\u53ef\u4ee5\u4e3a\u8fc7\u6e21\u8bbe\u7f6e\u5ef6\u8fdf\uff0c\u4f7f\u5f97\u8fc7\u6e21\u6548\u679c\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u540e\u5f00\u59cb\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  width: 200px;\n  height: 200px;\n  background-color: #3498db;\n  transition: width 1s ease 0.5s; \/* \u5ef6\u8fdf 0.5 \u79d2\u540e\u5f00\u59cb\u8fc7\u6e21 *\/\n}\n\ndiv:hover {\n  width: 400px;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u65f6\uff0c\u5143\u7d20\u7684\u5bbd\u5ea6\u53d8\u5316\u5c06\u4f1a\u5728 0.5 \u79d2\u7684\u5ef6\u8fdf\u540e\u5f00\u59cb\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>\u8fc7\u6e21\u7684 timing-function<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>timing-function<\/code> \u5c5e\u6027\u5b9a\u4e49\u4e86\u8fc7\u6e21\u7684\u901f\u5ea6\u66f2\u7ebf\uff0c\u5e38\u89c1\u7684\u503c\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ease<\/strong>\uff1a\u9ed8\u8ba4\u503c\uff0c\u8fc7\u6e21\u5f00\u59cb\u65f6\u6162\uff0c\u7ed3\u675f\u65f6\u6162\u3002<\/li>\n\n\n\n<li><strong>linear<\/strong>\uff1a\u5747\u5300\u8fc7\u6e21\uff0c\u901f\u5ea6\u4e0d\u53d8\u3002<\/li>\n\n\n\n<li><strong>ease-in<\/strong>\uff1a\u8fc7\u6e21\u5f00\u59cb\u65f6\u6162\u3002<\/li>\n\n\n\n<li><strong>ease-out<\/strong>\uff1a\u8fc7\u6e21\u7ed3\u675f\u65f6\u6162\u3002<\/li>\n\n\n\n<li><strong>ease-in-out<\/strong>\uff1a\u8fc7\u6e21\u5f00\u59cb\u548c\u7ed3\u675f\u65f6\u90fd\u6162\u3002<\/li>\n\n\n\n<li><strong>cubic-bezier(n,n,n,n)<\/strong>\uff1a\u81ea\u5b9a\u4e49\u8fc7\u6e21\u66f2\u7ebf\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u4f7f\u7528 <code>ease-in<\/code> \u8ba9\u5143\u7d20\u5f00\u59cb\u65f6\u6162\uff0c\u7ed3\u675f\u65f6\u5feb\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  width: 200px;\n  height: 200px;\n  background-color: #3498db;\n  transition: width 2s ease-in;\n}\n\ndiv:hover {\n  width: 400px;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>\u4f7f\u7528\u8fc7\u6e21\u521b\u5efa\u4ea4\u4e92\u6548\u679c<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fc7\u6e21\u6765\u521b\u5efa\u66f4\u590d\u6742\u7684\u4ea4\u4e92\u6548\u679c\uff0c\u4f8b\u5982\u6309\u94ae\u60ac\u505c\u6548\u679c\u3001\u76d2\u5b50\u9634\u5f71\u3001\u989c\u8272\u53d8\u5316\u7b49\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u6309\u94ae\u7684\u653e\u5927\u6548\u679c<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>button {\n  padding: 10px 20px;\n  font-size: 16px;\n  background-color: #3498db;\n  color: white;\n  border: none;\n  transition: transform 0.3s ease;\n}\n\nbutton:hover {\n  transform: scale(1.2); \/* \u6309\u94ae\u653e\u5927 *\/\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u9f20\u6807\u60ac\u505c\u5728\u6309\u94ae\u4e0a\u65f6\uff0c\u6309\u94ae\u4f1a\u5728 0.3 \u79d2\u5185\u653e\u5927 1.2 \u500d\uff0c\u4ea7\u751f\u52a8\u6001\u6548\u679c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. <strong>\u4f7f\u7528\u8fc7\u6e21\u4e0e <code>opacity<\/code><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e38\u89c1\u7684\u8fc7\u6e21\u6548\u679c\u662f\u6539\u53d8\u5143\u7d20\u7684\u900f\u660e\u5ea6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  opacity: 0;\n  background-color: #3498db;\n  width: 200px;\n  height: 200px;\n  transition: opacity 1s ease;\n}\n\ndiv:hover {\n  opacity: 1; \/* \u9f20\u6807\u60ac\u505c\u65f6\u9010\u6e10\u663e\u793a *\/\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\uff0c<code>div<\/code> \u5143\u7d20\u4f1a\u5728\u9f20\u6807\u60ac\u505c\u65f6\u9010\u6e10\u53d8\u5f97\u53ef\u89c1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9. <strong>\u7ec4\u5408\u8fc7\u6e21\u4e0e\u5176\u4ed6\u52a8\u753b<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fc7\u6e21\u662f\u7b80\u5355\u52a8\u753b\u7684\u6700\u4f73\u9009\u62e9\uff0c\u5982\u679c\u4f60\u9700\u8981\u66f4\u590d\u6742\u7684\u52a8\u753b\uff0c\u53ef\u4ee5\u4e0e <code>@keyframes<\/code> \u52a8\u753b\u7ed3\u5408\u4f7f\u7528\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7efc\u5408\u5b9e\u4f8b\uff1a\u6309\u94ae\u7684\u989c\u8272\u548c\u7f29\u653e\u6548\u679c<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n  &lt;title&gt;CSS3 \u8fc7\u6e21&lt;\/title&gt;\n  &lt;style&gt;\n    button {\n      padding: 10px 20px;\n      font-size: 16px;\n      background-color: #3498db;\n      color: white;\n      border: none;\n      cursor: pointer;\n      transition: background-color 0.4s, transform 0.2s;\n    }\n\n    button:hover {\n      background-color: #2ecc71;\n      transform: scale(1.1);\n    }\n  &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;button&gt;Hover Me!&lt;\/button&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5f53\u9f20\u6807\u60ac\u505c\u65f6\uff0c\u6309\u94ae\u7684\u80cc\u666f\u989c\u8272\u4f1a\u53d8\u5316\uff0c\u5e76\u4e14\u6309\u94ae\u4f1a\u8f7b\u5fae\u653e\u5927\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">CSS3 \u8fc7\u6e21\u662f\u5b9e\u73b0\u5143\u7d20\u5e73\u6ed1\u53d8\u6362\u7684\u5f3a\u5927\u5de5\u5177\u3002\u901a\u8fc7\u9002\u5f53\u7684\u4f7f\u7528\u8fc7\u6e21\u65f6\u95f4\u3001\u5ef6\u8fdf\u3001\u901f\u5ea6\u66f2\u7ebf\u7b49\uff0c\u53ef\u4ee5\u8ba9\u9875\u9762\u66f4\u52a0\u751f\u52a8\u548c\u4e92\u52a8\uff0c\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS3 \u8fc7\u6e21\uff08Transition\uff09\u5141\u8bb8\u4f60\u5728 CSS \u5c5e\u6027\u503c\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u6dfb\u52a0\u5e73\u6ed1\u7684\u52a8\u753b\u6548\u679c\u3002\u5b83\u4f7f\u5f97\u5143\u7d20\u4ece\u4e00\u4e2a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-1836","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=1836"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1836\/revisions"}],"predecessor-version":[{"id":1837,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1836\/revisions\/1837"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=1836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=1836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=1836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}