{"id":1838,"date":"2025-02-21T23:01:44","date_gmt":"2025-02-21T15:01:44","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=1838"},"modified":"2025-02-21T23:01:44","modified_gmt":"2025-02-21T15:01:44","slug":"css3-%e5%8a%a8%e7%94%bb","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/21\/css3-%e5%8a%a8%e7%94%bb\/","title":{"rendered":"CSS3 \u52a8\u753b"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">CSS3 \u52a8\u753b\uff08Animation\uff09\u662f\u53e6\u4e00\u79cd\u4f7f\u7f51\u9875\u5143\u7d20\u4ea7\u751f\u52a8\u6001\u6548\u679c\u7684\u65b9\u6cd5\uff0c\u6bd4\u8fc7\u6e21\u66f4\u4e3a\u5f3a\u5927\u548c\u7075\u6d3b\u3002\u901a\u8fc7 CSS \u52a8\u753b\uff0c\u4f60\u53ef\u4ee5\u8ba9\u5143\u7d20\u4ece\u4e00\u4e2a\u72b6\u6001\u8fc7\u6e21\u5230\u53e6\u4e00\u4e2a\u72b6\u6001\uff0c\u5e76\u4e14\u5728\u52a8\u753b\u8fc7\u7a0b\u4e2d\u8fdb\u884c\u591a\u6b21\u53d8\u5316\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\">CSS3 \u52a8\u753b\u4f7f\u7528 <code>@keyframes<\/code> \u6765\u5b9a\u4e49\u52a8\u753b\uff0c\u5e76\u901a\u8fc7 <code>animation<\/code> \u5c5e\u6027\u6765\u5e94\u7528\u52a8\u753b\u6548\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@keyframes animation-name {\n  from {\n    \/* \u521d\u59cb\u72b6\u6001 *\/\n    property: value;\n  }\n  to {\n    \/* \u7ed3\u675f\u72b6\u6001 *\/\n    property: value;\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u5b9a\u4e49\u52a8\u753b<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 CSS \u4e2d\uff0c<code>@keyframes<\/code> \u7528\u4e8e\u5b9a\u4e49\u52a8\u753b\u7684\u5173\u952e\u5e27\u3002\u6bcf\u4e2a\u5173\u952e\u5e27\u89c4\u5b9a\u4e86\u52a8\u753b\u67d0\u4e00\u65f6\u523b\u5143\u7d20\u7684\u6837\u5f0f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@keyframes moveRight {\n  0% {\n    transform: translateX(0);\n  }\n  100% {\n    transform: translateX(300px);\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u4f8b\u5b50\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a <code>moveRight<\/code> \u7684\u52a8\u753b\uff0c\u5143\u7d20\u4f1a\u4ece\u5f53\u524d\u4f4d\u7f6e\u5e73\u6ed1\u5730\u5411\u53f3\u79fb\u52a8 300px\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u5e94\u7528\u52a8\u753b<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4f7f\u7528\u52a8\u753b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 <code>animation<\/code> \u5c5e\u6027\u5c06\u52a8\u753b\u5e94\u7528\u5230\u67d0\u4e2a\u5143\u7d20\u4e0a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  width: 100px;\n  height: 100px;\n  background-color: #3498db;\n  animation: moveRight 2s ease-in-out infinite;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\uff0c<code>animation<\/code> \u5c5e\u6027\u7684\u503c\u6709\u51e0\u4e2a\u90e8\u5206\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>animation-name<\/strong>\uff1a\u52a8\u753b\u7684\u540d\u79f0\uff08\u8fd9\u91cc\u662f <code>moveRight<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>animation-duration<\/strong>\uff1a\u52a8\u753b\u7684\u6301\u7eed\u65f6\u95f4\uff08\u4f8b\u5982\uff1a<code>2s<\/code> \u8868\u793a 2 \u79d2\uff09\u3002<\/li>\n\n\n\n<li><strong>animation-timing-function<\/strong>\uff1a\u5b9a\u4e49\u52a8\u753b\u7684\u901f\u5ea6\u66f2\u7ebf\uff08\u4f8b\u5982\uff1a<code>ease-in-out<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>animation-iteration-count<\/strong>\uff1a\u52a8\u753b\u7684\u5faa\u73af\u6b21\u6570\uff08\u4f8b\u5982\uff1a<code>infinite<\/code> \u8868\u793a\u65e0\u9650\u5faa\u73af\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u52a8\u753b\u7684\u5c5e\u6027<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">CSS \u52a8\u753b\u6709\u5f88\u591a\u63a7\u5236\u5c5e\u6027\uff0c\u4ee5\u4e0b\u662f\u5e38\u7528\u7684\u51e0\u4e2a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>animation-name<\/strong>\uff1a\u6307\u5b9a\u5e94\u7528\u7684\u52a8\u753b\u540d\u79f0\u3002<\/li>\n\n\n\n<li><strong>animation-duration<\/strong>\uff1a\u52a8\u753b\u7684\u6301\u7eed\u65f6\u95f4\u3002<\/li>\n\n\n\n<li><strong>animation-timing-function<\/strong>\uff1a\u52a8\u753b\u7684\u52a0\u901f\u66f2\u7ebf\uff0c\u5e38\u7528\u7684\u503c\u6709 <code>linear<\/code>, <code>ease<\/code>, <code>ease-in<\/code>, <code>ease-out<\/code>, <code>ease-in-out<\/code>\u3002<\/li>\n\n\n\n<li><strong>animation-delay<\/strong>\uff1a\u8bbe\u7f6e\u52a8\u753b\u5f00\u59cb\u524d\u7684\u5ef6\u8fdf\u65f6\u95f4\u3002<\/li>\n\n\n\n<li><strong>animation-iteration-count<\/strong>\uff1a\u6307\u5b9a\u52a8\u753b\u7684\u64ad\u653e\u6b21\u6570\uff0c<code>infinite<\/code> \u8868\u793a\u65e0\u9650\u6b21\u64ad\u653e\u3002<\/li>\n\n\n\n<li><strong>animation-direction<\/strong>\uff1a\u5b9a\u4e49\u52a8\u753b\u7684\u64ad\u653e\u65b9\u5411\u3002\u5e38\u89c1\u503c\u6709\uff1a<\/li>\n\n\n\n<li><code>normal<\/code>\uff1a\u6309\u987a\u5e8f\u64ad\u653e\uff08\u9ed8\u8ba4\uff09\u3002<\/li>\n\n\n\n<li><code>reverse<\/code>\uff1a\u53cd\u5411\u64ad\u653e\u3002<\/li>\n\n\n\n<li><code>alternate<\/code>\uff1a\u6bcf\u6b21\u64ad\u653e\u5b8c\u4e00\u8f6e\u540e\u53cd\u5411\u64ad\u653e\u3002<\/li>\n\n\n\n<li><code>alternate-reverse<\/code>\uff1a\u6bcf\u6b21\u64ad\u653e\u5b8c\u4e00\u8f6e\u540e\u53cd\u5411\u64ad\u653e\uff0c\u4f46\u987a\u5e8f\u4e0e <code>reverse<\/code> \u76f8\u53cd\u3002<\/li>\n\n\n\n<li><strong>animation-fill-mode<\/strong>\uff1a\u6307\u5b9a\u52a8\u753b\u5728\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u5143\u7d20\u7684\u72b6\u6001\u3002\u5e38\u7528\u503c\u6709\uff1a<\/li>\n\n\n\n<li><code>forwards<\/code>\uff1a\u4fdd\u6301\u52a8\u753b\u7ed3\u675f\u65f6\u7684\u72b6\u6001\u3002<\/li>\n\n\n\n<li><code>backwards<\/code>\uff1a\u5728\u52a8\u753b\u5f00\u59cb\u524d\uff0c\u5143\u7d20\u4f7f\u7528\u5173\u952e\u5e27\u7684\u521d\u59cb\u6837\u5f0f\u3002<\/li>\n\n\n\n<li><code>both<\/code>\uff1a\u7ed3\u5408 <code>forwards<\/code> \u548c <code>backwards<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u7b80\u5355\u52a8\u753b\u793a\u4f8b<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u52a8\u753b\u793a\u4f8b\uff0c\u5b9a\u4e49\u4e00\u4e2a\u6309\u94ae\u7684\u5e73\u79fb\u52a8\u753b\uff1a<\/p>\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 \u52a8\u753b&lt;\/title&gt;\n  &lt;style&gt;\n    @keyframes moveRight {\n      0% {\n        transform: translateX(0);\n      }\n      100% {\n        transform: translateX(200px);\n      }\n    }\n\n    button {\n      width: 100px;\n      height: 50px;\n      background-color: #3498db;\n      color: white;\n      border: none;\n      font-size: 16px;\n      cursor: pointer;\n      animation: moveRight 2s ease-in-out infinite;\n    }\n  &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;button&gt;Click 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\u4f8b\u5b50\u4e2d\uff0c\u6309\u94ae\u4f1a\u5728 2 \u79d2\u5185\u5e73\u6ed1\u5730\u5411\u53f3\u79fb\u52a8 200px\uff0c\u5e76\u4e14\u8fd9\u4e2a\u52a8\u753b\u4f1a\u4e00\u76f4\u5faa\u73af\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>\u591a\u4e2a\u5173\u952e\u5e27\uff08Keyframes\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>@keyframes<\/code> \u5141\u8bb8\u4f60\u5b9a\u4e49\u591a\u4e2a\u5173\u952e\u5e27\uff0c\u521b\u5efa\u66f4\u590d\u6742\u7684\u52a8\u753b\u6548\u679c\u3002\u4f8b\u5982\uff0c\u8ba9\u4e00\u4e2a\u5143\u7d20\u5148\u53d8\u5927\uff0c\u7136\u540e\u53d8\u5c0f\uff0c\u6700\u540e\u6062\u590d\u539f\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@keyframes scaleUpDown {\n  0% {\n    transform: scale(1);\n  }\n  50% {\n    transform: scale(1.5);\n  }\n  100% {\n    transform: scale(1);\n  }\n}\n\ndiv {\n  width: 100px;\n  height: 100px;\n  background-color: #3498db;\n  animation: scaleUpDown 3s ease-in-out infinite;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>\u52a8\u753b\u7ec4\u5408<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u5c06\u591a\u4e2a\u52a8\u753b\u6548\u679c\u7ec4\u5408\u5230\u4e00\u4e2a\u5143\u7d20\u4e0a\uff0c\u5b9a\u4e49\u591a\u4e2a <code>@keyframes<\/code> \u548c <code>animation<\/code> \u5c5e\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@keyframes moveAndFade {\n  0% {\n    transform: translateX(0);\n    opacity: 1;\n  }\n  100% {\n    transform: translateX(300px);\n    opacity: 0;\n  }\n}\n\ndiv {\n  width: 100px;\n  height: 100px;\n  background-color: #3498db;\n  animation: moveAndFade 3s ease-in-out infinite;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5143\u7d20\u4f1a\u5728 3 \u79d2\u5185\u5e73\u6ed1\u5730\u5411\u53f3\u79fb\u52a8\uff0c\u5e76\u4e14\u6e10\u6e10\u53d8\u900f\u660e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. <strong>\u4f7f\u7528\u52a8\u753b\u4e0e\u8fc7\u6e21\u7684\u7ed3\u5408<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fc7\u6e21\u548c\u52a8\u753b\u53ef\u4ee5\u7ec4\u5408\u4f7f\u7528\uff0c\u5236\u4f5c\u66f4\u4e30\u5bcc\u7684\u6548\u679c\u3002\u4f8b\u5982\uff0c\u5f53\u9f20\u6807\u60ac\u505c\u65f6\uff0c\u5143\u7d20\u4e0d\u4ec5\u53d8\u5316\u989c\u8272\uff0c\u8fd8\u53ef\u4ee5\u589e\u52a0\u52a8\u753b\u6548\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@keyframes moveUp {\n  0% {\n    transform: translateY(0);\n  }\n  100% {\n    transform: translateY(-50px);\n  }\n}\n\ndiv {\n  width: 200px;\n  height: 200px;\n  background-color: #3498db;\n  transition: background-color 0.3s;\n}\n\ndiv:hover {\n  background-color: #2ecc71;\n  animation: moveUp 0.5s forwards;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>div<\/code> \u5143\u7d20\u4f1a\u5728\u60ac\u505c\u65f6\u5148\u53d8\u5316\u80cc\u666f\u989c\u8272\uff0c\u7136\u540e\u5411\u4e0a\u5e73\u79fb\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7efc\u5408\u5b9e\u4f8b\uff1a\u6309\u94ae\u70b9\u51fb\u65f6\u7684\u52a8\u753b\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 \u52a8\u753b&lt;\/title&gt;\n  &lt;style&gt;\n    @keyframes clickEffect {\n      0% {\n        transform: scale(1);\n        background-color: #3498db;\n      }\n      50% {\n        transform: scale(1.2);\n        background-color: #2ecc71;\n      }\n      100% {\n        transform: scale(1);\n        background-color: #3498db;\n      }\n    }\n\n    button {\n      width: 150px;\n      height: 50px;\n      background-color: #3498db;\n      color: white;\n      border: none;\n      font-size: 16px;\n      cursor: pointer;\n      animation: none;\n    }\n\n    button:active {\n      animation: clickEffect 0.3s ease;\n    }\n  &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;button&gt;Click Me&lt;\/button&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6309\u94ae\u5728\u70b9\u51fb\u65f6\u4f1a\u5148\u653e\u5927\u5e76\u6539\u53d8\u989c\u8272\uff0c\u7136\u540e\u6062\u590d\u539f\u72b6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">CSS3 \u52a8\u753b\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u4e14\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u52a8\u6001\u6548\u679c\uff0c\u4e0d\u9700\u8981 JavaScript \u53c2\u4e0e\u5373\u53ef\u5b9e\u73b0\u4e30\u5bcc\u7684\u52a8\u753b\u6548\u679c\u3002\u901a\u8fc7 <code>@keyframes<\/code> \u5b9a\u4e49\u591a\u4e2a\u5173\u952e\u5e27\uff0c\u914d\u5408 <code>animation<\/code> \u5c5e\u6027\uff0c\u4f60\u53ef\u4ee5\u63a7\u5236\u52a8\u753b\u7684\u884c\u4e3a\u3001\u65f6\u95f4\u3001\u5ef6\u8fdf\u3001\u91cd\u590d\u6b21\u6570\u7b49\uff0c\u521b\u5efa\u51fa\u5404\u79cd\u52a8\u611f\u5341\u8db3\u7684\u9875\u9762\u6548\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS3 \u52a8\u753b\uff08Animation\uff09\u662f\u53e6\u4e00\u79cd\u4f7f\u7f51\u9875\u5143\u7d20\u4ea7\u751f\u52a8\u6001\u6548\u679c\u7684\u65b9\u6cd5\uff0c\u6bd4\u8fc7\u6e21\u66f4\u4e3a\u5f3a\u5927\u548c\u7075\u6d3b\u3002\u901a\u8fc7 CSS  [&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-1838","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1838","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=1838"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1838\/revisions"}],"predecessor-version":[{"id":1839,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1838\/revisions\/1839"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=1838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=1838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=1838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}