CSS @keyframes กฎ
- หน้าก่อน justify-self
- หน้าต่อไป @layer
การระบุและวิธีใช้
ผ่านกฎ @keyframes คุณสามารถสร้างแอนิเมชัน。
หลักการที่ทำให้เกิดแอนิเมชันคือ ให้รูปแบบ CSS หนึ่งเปลี่ยนแปลงเรียบร้อยเป็นรูปแบบ CSS อีกหนึ่ง。
ในระหว่างแอนิเมชัน คุณสามารถเปลี่ยนรูปแบบ CSS หลายครั้ง。
ใช้เปอร์เซ็นต์เพื่อกำหนดเวลาที่เกิดการเปลี่ยนแปลง หรือผ่านประโยคคำเรียก "from" และ "to" ที่เท่ากับ 0% และ 100%。
0% คือเวลาที่เริ่มแอนิเมชัน 100% คือเวลาที่สิ้นสุดแอนิเมชัน。
คำเตือน:เพื่อรับการสนับสนุนที่ดีที่สุดจากเว็บเบราเซอร์ คุณควรเสมอนั้นทั้ง 0% และ 100% ตัวเลือกตัวเลข。
คำเตือน:ใช้คุณสมบัติแอนิเมชันเพื่อควบคุมรูปแบบแอนิเมชัน และเชื่อมโยงแอนิเมชันกับเลือกตัวเลข。
注意:!important กฎถูกละเลยในเวลาที่เฟิร์นแบบ (ดูตัวอย่างสุดท้ายบนหน้านี้)。
ดูเพิ่มเติมที่
CSS3 ตัวเรียนCSS3 อนิมาชั่น
ตัวอย่าง
ตัวอย่าง 1
使 div 元素匀速向下移动:
@keyframes mymove { 从 {top: 0px;} 至 {top: 200px;} }
例子 2
在一个动画中添加多个 keyframe 选择器:
@keyframes mymove { 0% {top: 0px;} 25% {top: 200px;} 50% {top: 100px;} 75% {top: 200px;} 100% {top: 0px;} }
例子 3
在一个动画中改变多个 CSS 样式:
@keyframes mymove { 0% {top: 0px; background: red; width: 100px;} 100% {top: 200px; background: yellow; width: 300px;} }
例子 4
带有多个 CSS 样式的多个 keyframe 选择器:
@keyframes mymove { 0% {top: 0px; left: 0px; background: red;} 25% {top: 0px; left: 100px; background: blue;} 50% {top: 100px; left: 100px; background: yellow;} 75% {top: 100px; left: 0px; background: green;} 100% {top: 0px; left: 0px; background: red;} }
例子 5
注意:!important 规则在关键帧中被忽略:
@keyframes myexample { 从 {top: 0px;} 50% {top: 100px !important;} /* 被忽略 */ 至 {top: 200px;} }
CSS 语法
@keyframes animationname {keyframes-selector {css-styles;}}
属性值
值 | 描述 |
---|---|
animationname | 必需。定义动画的名称。 |
keyframes-selector |
必需。动画时长的百分比。 合法的值:
|
css-styles | 必需。一个或多个合法的 CSS 样式属性。 |
浏览器的支持
Chrome | IE / Edge | Firefox | Safari | Opera |
---|---|---|---|---|
43.0 4.0 -webkit- |
10.0 | 16.0 5.0 -moz- |
9.0 4.0 -webkit- |
30.0 15.0 -webkit- 12.0 -o- |
- หน้าก่อน justify-self
- หน้าต่อไป @layer