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
అనిమేషన్ బ్రౌజర్ మద్దతు
పట్టికలో ఇన్ని పట్టికలో అనిమేషన్ అట్రిబ్యూట్ను పూర్తిగా మద్దతు ఇచ్చే మొదటి బ్రౌజర్ సంస్కరణ పేర్కొన్నారు.
అట్రిబ్యూట్ | చ్రోమ్ | ఐఈ | ఫైర్ఫాక్స్ | సఫారీ | ఓపెరా |
---|---|---|---|---|---|
@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" అనిమేషన్ను <div> ఎలిమెంట్పై బ్యాండ్ చేస్తాము. అనిమేషన్ 4 సెకన్లు కాగా, <div> ఎలిమెంట్ బ్యాక్గ్రౌండ్కలర్ నుండి "red" మరియు "yellow" వరకు క్రమంగా మారుతుంది:
ఉదాహరణ
/* అనిమేషన్ కోడ్ */ @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
- అనిమేషన్-డయరెషన్ మరియు అనిమేషన్-ఇటరేషన్-కాంట్ ఆధారంగా అనిమేషన్ లాస్ట్ క్లీషన్ ఫ్రేమ్ స్టైల్ విలువలను కాపాడుతుంది.backwards
- అనిమేషన్-డయరెషన్ ఆధారంగా మొదటి క్లీషన్ ఫ్రేమ్ స్టైల్ విలువలను అనిమేషన్ డలేషన్ వ్యవధిలో కాపాడుతుంది.both
- అనిమేషన్ అన్ని దిశలలో సమానంగా పాటిస్తుంది మరియు రెండు దిశలలో అనిమేషన్ అట్రిబ్యూట్స్ విస్తరిస్తుంది.
ఈ ఉదాహరణ డివై ఎలమెంట్ అనిమేషన్ ముగిసిన క్లీషన్ ఫ్రేమ్ నుండి స్టైల్ విలువలను కాపాడుతుంది:
ఉదాహరణ
div { width: 100px; height: 100px; background: red; position: relative; animation-name: example; animation-duration: 3s; animation-fill-mode: forwards; }
ఈ ఉదాహరణలో అనిమేషన్ డిలే కాలంలో అనిమేషన్ ప్రారంభం ముందు <div> ఎలంజంట్ మొదటి కీ ఫ్రేమ్ స్టైల్ విలువను పొందుతుంది:
ఉదాహరణ
div { width: 100px; height: 100px; background: red; position: relative; animation-name: example; animation-duration: 3s; animation-delay: 2s; animation-fill-mode: backwards; }
ఈ ఉదాహరణలో అనిమేషన్ ప్రారంభం ముందు <div> ఎలంజంట్ మొదటి కీ ఫ్రేమ్ స్టైల్ విలువను పొందుతుంది, అనిమేషన్ ముగిసిన తర్వాత చివరి కీ ఫ్రేమ్ స్టైల్ విలువను ఉంచుతుంది:
ఉదాహరణ
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 పరికరాలు మరియు అన్ని 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 టూల్టిప్