css动画是由关键帧、动画属性和css属性三部分组成的。关键帧用于定义动画在不同阶段的状态;动画属性用于决定动画的播放时长,播放次数,以及用何种函数式去播放动画等;css属性用于指定css元素在不同关键帧下的状态。
本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。
css动画是由三部分组成,分别为关键帧(keyframes)、动画属性(properties)、css属性。
关键帧(keyframes) - 定义动画在不同阶段的状态。
动画属性(properties) - 决定动画的播放时长,播放次数,以及用何种函数式去播放动画等。(可以类比音视频播放器)
css属性 - 指定css元素不同关键帧下的状态。
1、关键帧
使用@keyframes规则指定,可以用来定义CSS动画的一个周期的行为,可以创建简单的动画。
动画与转换类似,因为它们都是随时间改变CSS属性的表示值。主要区别在于,当属性值更改时(例如,当悬停时属性值发生改变时),转换会隐式的触发,但在应用动画属性时会显式执行动画。因此,动画需要显示动画属性的显式值。这些值是在@keyframes规则中指定的动画关键帧定义的。因此,@keyframes规则里是由一组封装的CSS样式规则组成的,这些规则描述了属性值如何随时间变化。
2、动画属性
通过@keyframes创建了动画,就需要animation(动画)属性将动画应用于元素,并设置动画迭代的次数,是否在开始和结束值之间交替,以及动画是否应该运行或暂停。
动画属性可以理解为播放器的相关功能,一个最基本的播放器应该具有:播放/暂停、播放时长、播放顺序(逆序/正序/交替播放)、循环次数等。
animation:
[animation-name] [animation-duration] // 动画的名称、持续时间
[animation-timing-function][animation-delay] // 关于时间的函数(properties/t)、延迟时间
[animation-iteration-count] [animation-direction] // 播放次数、播放顺序
[animation-fill-mode] [animation-play-state]; // 播放前或停止后设置相应样式、控制动画运行或暂停
关键帧 动画属性的语法:
/* 定义动画*/ @keyframes 动画名称{ /* 样式规则*/ } /* 将它应用于元素 */ .element { animation-name: 动画名称(在@keyframes中已经声明好的); /* 或使用动画简写属性*/ animation: 动画名称 1s ... }
在@keyframes规则的大括号里有什么?
在大括号中,我们需要定义关键帧或航点,这些关键帧或航点指定在动画期间的特定点处正在动画化的属性的值。这允许我们控制动画序列中的中间步骤。例如,一个简单动画的@keyframe可以是这样:
@keyframes change-bg-color { 0% { background-color: red; } 50% { background-color: blue; } 100%{ background-color: red; } } .demo{ -webkit-animation:change-bg-color 5s infinite; animation: change-bg-color 5s infinite; }
运行效果:
'0%'、‘50%’、'100%'都是关键帧选择器,每个选择器定义一个关键帧规则。关键帧规则的关键帧声明块由属性和值组成。
上述动画类似于简单的过渡效果:背景颜色从动画开头的一个值(0%)开始变化,在中间达到一个值(50%),在动画结束时达到另一个值(100%)。“0%”、”50%”和“100%”关键帧选择器定义了希望动画属性更改值的航点或百分点。我们也可以使用选择器关键字 from,to而不是分别使用0%和100%,它们是等效的。
@keyframes change-bg-color { from{ background-color: red; } 50% { background-color: blue; } to{ background-color: red; } }
关键帧选择器由一个或多个以逗号分隔的百分比值或from和to关键字组成。请注意,百分比单位说明符必须用于百分比值。因此,'0'是无效的关键帧选择器。
以下是具有关键帧选择器的动画示例,其中包括多个以逗号分隔的百分比值和/或关键字关键帧选择器from和to。
@keyframes bouncing { 0%, 50%, 100% { /* 或者 from, 50%, to */ top: 0; } 25%, 75% { top: 100px; } }
上面的@keyframes规则定义:元素的顶部偏移量在开始时,中途和动画结束时将等于零,并且它将四分之一和四分之三路径时等于100px; 这意味着元素在动画循环中上下移动了好几次。
(学习视频分享:css视频教程)
以上是css动画是由什么组成的详细内容。更多信息请关注PHP中文网其他相关文章!

No,youshouldn'tusemultipleIDsinthesameDOM.1)IDsmustbeuniqueperHTMLspecification,andusingduplicatescancauseinconsistentbrowserbehavior.2)Useclassesforstylingmultipleelements,attributeselectorsfortargetingbyattributes,anddescendantselectorsforstructure

html5aimstoenhancewebcapabilities,Makeitmoredynamic,互动,可及可访问。1)ITSupportsMultimediaElementsLikeAnd,消除innewingtheneedtheneedtheneedforplugins.2)SemanticeLelelemeneLementelementsimproveaCceccessibility inmproveAccessibility andcoderabilitile andcoderability.3)emply.3)lighteppoperable popperappoperable -poseive weepivewebappll

html5aimstoenhancewebdevelopmentanduserexperiencethroughsemantstructure,多媒体综合和performanceimprovements.1)SemanticeLementLike like,和ImproVereAdiability and ImproVereAdabilityAncccossibility.2)和TagsallowsemplowsemplowseamemelesseamlessallowsemlessemlessemelessmultimedimeDiaiiaemediaiaembedwitWithItWitTplulurugIns.3)

html5isnotinerysecure,butitsfeaturescanleadtosecurityrisksifmissusedorimproperlyimplempled.1)usethesand andboxattributeIniframestoconoconoconoContoContoContoContoContoconToconToconToconToconToconTedContDedContentContentPrevulnerabilityLikeClickLickLickLickLickLickjAckJackJacking.2)

HTML5aimedtoenhancewebdevelopmentbyintroducingsemanticelements,nativemultimediasupport,improvedformelements,andofflinecapabilities,contrastingwiththelimitationsofHTML4andXHTML.1)Itintroducedsemantictagslike,,,improvingstructureandSEO.2)Nativeaudioand

使用ID选择器在CSS中并非固有地不好,但应谨慎使用。1)ID选择器适用于唯一元素或JavaScript钩子。2)对于一般样式,应使用类选择器,因为它们更灵活和可维护。通过平衡ID和类的使用,可以实现更robust和efficient的CSS架构。

html5'sgoalsin2024focusonrefinement和optimization,notnewfeatures.1)增强performandemandeffifice throughOptimizedRendering.2)risteccessibilitywithrefinedibilitywithRefineDatientAttributesAndEllements.3)expliencernsandelements.3)explastsecurityConcerns,尤其是withercervion.4)

html5aimedtotoimprovewebdevelopmentInfourKeyAreas:1)多中心供应,2)语义结构,3)formcapabilities.1)offlineandstorageoptions.1)html5intoryements html5introctosements introdements and toctosements and toctosements,简化了inifyingmediaembedingmediabbeddingingandenhangingusexperience.2)newsements.2)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

SublimeText3汉化版
中文版,非常好用

Dreamweaver Mac版
视觉化网页开发工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!