CSS လှည့်ပတ်
- အရှေ့အစီအစဉ် CSS ဆောင်ရွက်
- နောက်အစီအစဉ် CSS အကြောင်းဆို
CSS လှည့်ပတ်
CSS 可实现 HTML 元素的动画效果,而不使用 JavaScript 或 Flash!
在本章中,您将学习如下属性:
@keyframes
animation-name
animation-duration
animation-delay
animation-iteration-count
animation-direction
animation-timing-function
animation-fill-mode
animation
对动画的浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
အချိန်အား | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
@keyframes | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |
animation-name | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |
animation-duration | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |
animation-delay | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |
animation-iteration-count | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |
animation-direction | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |
animation-timing-function | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |
animation-fill-mode | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |
animation | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |
什么是 CSS 动画?
动画使元素逐渐从一种样式变为另一种样式。
您可以随意更改任意数量的 CSS 属性。
如需使用 CSS 动画,您必须首先为动画指定一些关键帧。
关键帧包含元素在特定时间所拥有的样式。
@keyframes 规则
如果您在 @keyframes
规则中指定了 CSS 样式,动画将在特定时间逐渐从当前样式更改为新样式。
要使动画生效,必须将动画绑定到某个元素。
下面的例子将 "example" 动画绑定到
အမျိုးအမိုး
/* 动画代码 */ @keyframes example { from {background-color: red;} to {background-color: yellow;} } /* 向此元素应用动画效果 */ div { width: 100px; height: 100px; background-color: red; animation-name: example; animation-duration: 4s; }
မှတ်ချက်:animation-duration
အကျိုးသတ်မှတ် အချိန် အရ လှုပ်ရှား ပြုလိုက်ပါ၏။ အကျိုးသတ်မှတ် အချိန် အရ အသုံးပြု လိုသေးသည်。 animation-duration
အကျိုးသတ်မှတ် အချိန် အရ လှုပ်ရှား မပြုလိမ့်မည် သေးသည်။ အရေးသတ်သည့် အကျိုးသတ်မှတ် အချိန် အရ အချိန် 0s (0 စက္ကန့်) ဖြစ်သည်。
အရေးသတ်သည့် အကျိုးသတ်မှတ် အချိန် အစ နှင့် အပြီး အထိ ပြောင်းလဲသွားမည် ဟူသော "from" နှင့် "to" သတ်မှတ်သည် (0% စတင် 100% အပြီး) အခါ အကျိုးသတ်မှတ် အသုံးပြု ပြီး ပြောင်းလဲသွားမည် ကို ကြိုးပမ်းလိုက်ပါသည်。
သို့မဟုတ် ရာချိန် တိုင်း သုံး နိုင်ပါသည်။ ရာချိန် သုံး လိုက်လျှင် အကျိုးသတ်မှတ် အသုံးပြု နိုင်သော အောက်ပါ အကျိုးသတ်မှတ် အရာများ အသုံးပြု နိုင်ပါသည်。
အောက်ပါ အကျိုးသတ်မှတ် သည် လှုပ်ရှား 25% အပြီးသတ် 50% အပြီးသတ် နှင့် လှုပ်ရှား 100% အပြီးသတ် အခါ အကွက် <div> အဆိုပါ နေရာ များ အရေးယူပုံ ပြောင်းလဲလိမ့်မည်:
အမျိုးအမိုး
/* 动画代码 */ @keyframes example { 0% {background-color: red;} 25% {background-color: yellow;} 50% {background-color: blue;} 100% {background-color: green;} } /* 应用动画的元素 */ div { width: 100px; height: 100px; background-color: red; animation-name: example; animation-duration: 4s; }
下面的例子将在动画完成 25%,完成 50% 以及动画完成 100% 时更改背景颜色和
အမျိုးအမိုး
/* 动画代码 */ @keyframes example { 0% {background-color:red; left:0px; top:0px;} 25% {background-color:yellow; left:200px; top:0px;} 50% {background-color:blue; left:200px; top:200px;} 75% {background-color:green; left:0px; top:200px;} 100% {background-color:red; left:0px; top:0px;} } /* 应用动画的元素 */ div { width: 100px; height: 100px; position: relative; background-color: red; animation-name: example; animation-duration: 4s; }
延迟动画
animation-delay
属性规定动画开始的延迟时间。
下面的例子在开始动画前有 2 秒的延迟:
အမျိုးအမိုး
div { width: 100px; height: 100px; position: relative; background-color: red; animation-name: example; animation-duration: 4s; animation-delay: 2s; }
负值也是允许的。如果使用负值,则动画将开始播放,如同已播放 N 秒。
在下面的例子中,动画将开始播放,就好像它已经播放了 2 秒钟一样:
အမျိုးအမိုး
div { width: 100px; height: 100px; position: relative; background-color: red; animation-name: example; animation-duration: 4s; animation-delay: -2s; }
设置动画应运行多少次
animation-iteration-count
属性指定动画应运行的次数。
下面的例子在停止前把动画运行 3 次:
အမျိုးအမိုး
div { width: 100px; height: 100px; position: relative; background-color: red; animation-name: example; animation-duration: 4s; animation-iteration-count: 3; }
下面的例子使用值 "infinite" 使动画永远持续下去:
အမျိုးအမိုး
div { width: 100px; height: 100px; position: relative; background-color: red; animation-name: example; animation-duration: 4s; animation-iteration-count: infinite; }
反向或交替运行动画
animation-direction
属性指定是向前播放、向后播放还是交替播放动画。
animation-direction
属性可接受以下值:
normal
- 动画正常播放(向前)。默认值reverse
- 动画以反方向播放(向后)alternate
- 动画先向前播放,然后向后alternate-reverse
- 动画先向后播放,然后向前
下例将以相反的方向(向后)运行动画:
အမျိုးအမိုး
div { width: 100px; height: 100px; position: relative; background-color: red; animation-name: example; animation-duration: 4s; animation-direction: reverse; }
下面的例子使用值 "alternate" 使动画先向前运行,然后向后运行:
အမျိုးအမိုး
div { width: 100px; height: 100px; position: relative; background-color: red; animation-name: example; animation-duration: 4s; animation-iteration-count: 2; animation-direction: alternate; }
下面的例子使用值 "alternate-reverse" 使动画先向后运行,然后向前运行:
အမျိုးအမိုး
div { width: 100px; height: 100px; position: relative; background-color: red; animation-name: example; animation-duration: 4s; animation-iteration-count: 2; animation-direction: alternate-reverse; }
指定动画的速度曲线
animation-timing-function
属性规定动画的速度曲线。
animation-timing-function
属性可接受以下值:
ease
- 指定从慢速开始,然后加快,然后缓慢结束的动画(默认)linear
- 规定从开始到结束的速度相同的动画ease-in
- 规定慢速开始的动画ease-out
- 规定慢速结束的动画ease-in-out
- 指定开始和结束较慢的动画cubic-bezier(n,n,n,n)
- သင်သည် သုံးစွဲနိုင်သော သုံးဆုံး ဘက်စီယံ ပြောင်းလဲခြင်း များ အောက်မှာ သင်သည် သင်၏ အရိုးများ ကို ကိုးကွယ်နိုင်သည်
အောက်ပါ အကျိုးသတ်မှတ်ချက်များကို ဖော်ပြသည်မှာ အသုံးပြုနိုင်သော မတူညီသော အသားချက် အရာများကို ပြသည်
အမျိုးအမိုး
#div1 {animation-timing-function: linear;} #div2 {animation-timing-function: ease;} #div3 {animation-timing-function: ease-in;} #div4 {animation-timing-function: ease-out;} #div5 {animation-timing-function: ease-in-out;}
လှည့်ပြခြင်း အသိမ်းအပြန် အချက်အရာ
CSS လှည့်ပြခြင်း သည် ပထမဆုံး အခြေခံအချက်အရာ ဖြစ်ပေါ်ခြင်း အခြား နှင့် နောက်ဆုံး အခြေခံအချက်အရာ ဖြစ်ပေါ်ခြင်း အတွင်း အကွက်အား အခြေခံအချက်အရာများ အောက်မှာ အခြေခံအချက်အရာများ အသုံးပြုခြင်း မပြုပါ။animation-fill-mode
အရေးယူဆောင်ရွက်ခြင်း အချက်အရာများ အား ဖြေရှင်းနိုင်သည်。
လှည့်ပြခြင်း မဖြစ်ပေါ်မီ (စတင်ခြင်း အခြား နှင့် အပြီးခြင်း အခြား နှင့် ဆိုင်၍ သို့မဟုတ် နှစ်ခုစလုံး အပြီးခြင်း)animation-fill-mode
အခြေခံ အကွက်အား အထိုအချက်အရာများ အောက်မှာ အချက်အရာများ အသုံးပြုခြင်း အချက်အရာ
animation-fill-mode အရေးယူဆောင်ရွက်ခြင်း အမှတ်အသားများ အောက်ပါအတိုင်း လိုက်နာနိုင်သည်
none
- မူကြမ်း အဖွဲ့အစည်းအဖြစ်။ လှည့်ပြခြင်း ပြုလုပ်ခြင်းအပြီးတွင် အကွက်အား အထိုအချက်အရာများ သုံးစွဲခြင်း မပြုပါ။forwards
- အကွက်သည် နောက်ဆုံး အခြေခံအချက်အရာမှ အထိုအချက်အရာများကို သိမ်းဆည်းရမည်ဖြစ်သည် (animation-direction နှင့် animation-iteration-count အောက်မှာ အမြတ်အသွား)。backwards
- အကွက်သည် ပထမဆုံး အခြေခံအချက်အရာမှ အထိုအချက်အရာများကို ရရှိရမည်ဖြစ်သည် (animation-direction အောက်မှာ အမြတ်အသွား) နှင့် လှည့်ပြခြင်း အချိန်ကြာခြင်း အတွင်း အထို အချက်အရာများကို သိမ်းဆည်းရမည်ဖြစ်သည်。both
- လှည့်ပြခြင်းသည် အရှေ့သို့ နှင့် နောက်သို့ နှစ်ခုစလုံး အားလုံး လိုက်နာရမည်ဖြစ်သည်။
အောက်ပါ အကျိုးသတ်မှတ်ချက်များကို ဖော်ပြသည်မှာ <div> အကွက်ကို လှည့်ပြီး လှည့်ပြခြင်းအပြီးတွင် နောက်ဆုံး အခြေခံအချက်အရာများမှ အထိုအချက်အရာများကို သိမ်းဆည်းရမည်ဖြစ်သည့်အပြင်
အမျိုးအမိုး
div { width: 100px; height: 100px; background: red; position: relative; animation-name: example; animation-duration: 3s; animation-fill-mode: forwards; }
ဒီ အမျိုးအမိုး အချိန်အား ကို အချိန်တစ်ခု ပြောင်းလဲခြင်း မရှိသော အချိန် အတွက် အဆိုပါ အအိုက်အတ္တံ အအိုက်အတ္တံ ကို သတ်မှတ်ထားသည်။
အမျိုးအမိုး
div { width: 100px; height: 100px; background: red; position: relative; animation-name: example; animation-duration: 3s; animation-delay: 2s; animation-fill-mode: backwards; }
ဒီ အမျိုးအမိုး အချိန်အား ကို အချိန်တစ်ခု ပြောင်းလဲခြင်း မရှိသော အချိန် အတွက် အဆိုပါ အအိုက်အတ္တံ အအိုက်အတ္တံ ကို သတ်မှတ်ထားသည်။
အမျိုးအမိုး
div { width: 100px; height: 100px; background: red; position: relative; animation-name: example; animation-duration: 3s; animation-delay: 2s; animation-fill-mode: both; }
အလင်းပတ် အချိန်အား အလုပ်အထိုး
ဒီ အမျိုးအမိုး အချိန်အား ကို သုံးပြီး ရှိသော အချိန်အား ကို ဖော်ပြထားသည်။
အမျိုးအမိုး
div { animation-name: example; animation-duration: 5s; animation-timing-function: linear; animation-delay: 2s; animation-iteration-count: infinite; animation-direction: alternate; }
အလုပ်အထိုး animation
ဒီ အချိန်အား အလင်းပတ် အကျိုးသတ္တိ ကို ပြုလုပ်နိုင်သော အချိန်အား ကို အလုပ်အထိုး သတ်မှတ်ထားသည်။
အမျိုးအမိုး
div { animation: example 5s linear 2s infinite alternate; }
CSS အလင်းပတ် အချိန်အား
ဒီ အချိန်အား အချက်အလက်များ နှင့် အလင်းပတ် အချိန်အား ကို ဖော်ပြထားသည်။
အချိန်အား | ကြည့်ရှုရန် |
---|---|
@keyframes | အလင်းပတ် အချိန်အား သတ်မှတ်ထားသည်။ |
animation | အလင်းပတ် အချိန်အား ပေါင်းစပ်ထားသည်။ |
animation-delay | အလင်းပတ် စတင်ခြင်း အချိန်အား သတ်မှတ်ထားသည်။ |
animation-direction | အလင်းပတ် ပြောင်းလဲခြင်း သည် အရွယ်ထွက်လာမည်ကို သတ်မှတ်ထားသည်။ |
animation-duration | အလင်းပတ် အချိန်အား အလုပ်အထိုး သတ်မှတ်ထားသည်။ |
animation-fill-mode | အလင်းပတ် ပြောင်းလဲခြင်း မရှိသော အချိန် အတွက် အဆိုပါ အအိုက်အတ္တံ အအိုက်အတ္တံ ကို သတ်မှတ်ထားသည်။ |
animation-iteration-count | အမျိုးအမိုး အလင်းပတ်သည် ပြောင်းလဲသော ကြိမ်နှုန်းကို သတ်မှတ်ထားသည်။ |
animation-name | ဒီ @keyframes အမျိုးအမိုး အလင်းပတ်သတ်ထားသည်။ |
animation-play-state | လှည့်ပတ် ကို တိုးမြှင့် သို့မဟုတ် ကန့်သတ်ကြောင်း ကြိုးပမ်း |
animation-timing-function | လှည့်ပတ် အစီအစဉ် အစား အသား ကို ကြိုးပမ်း |
- အရှေ့အစီအစဉ် CSS ဆောင်ရွက်
- နောက်အစီအစဉ် CSS အကြောင်းဆို