百科狗-知识改变命运!
--

animation - 动画特效 - css 动画

是丫丫呀1年前 (2023-11-21)阅读数 19#技术干货
文章标签属性

animation

版本:CSS3

CSSanimation属性是animation-nameanimation-duration,animation-timing-functionanimation-delayanimation-iteration-countanimation-directionanimation-fill-modeanimation-play-state属性的一个简写属性形式。

示例

/* @keyframes duration  |  timing-function  |  delay  | 
   iteration-count  |  direction  |  fill-mode  |  play-state  |  name */
animation: 3s ease-in 1s 2 reverse both paused slidein;

/* @keyframes duration  |  timing-function  |  delay  |  name */
animation: 3s linear 1s slidein;

/* @keyframes duration  |  name */
animation: 3s slidein;

浏览器支持

IE10以上版本的浏览器都支持animation

语法

animation:|||

animation属性用来指定一组或多组动画,每组之间用逗号相隔。

每组动画规定的属性如下:

  • 以下属性出现0次或1次:
  • animation 的 name 值可能是:none
  • 可能会出现0、1 或 2 次

每个动画定义中的属性值的顺序很重要:可以被解析为的第一个值被分配给animation-duration,第二个分配给animation-delay

每个动画定义中的值的顺序,对于区分animation-name值与其他关键字也很重要。解析时,对于除animation-name之外的有效的关键字,必须被前面的简写中没有找到值的属性所接受。此外,在序列化时,animation-name与以及其他属性值做区分等情况下,必须输出其他属性的默认值。

取值

  • :动画播放的次数。该值必须是animation-iteration-count可用的值之一。
  • :动画播放的方向。该值必须是animation-direction可用的值之一。
  • :确定动画在执行之前和之后这两个阶段应用的样式。该值必须是animation-fill-mode可用的值之一。
  • :确定动画是否正在播放。该值必须是animation-play-state中可用的值之一。
默认值看每个独立属性
适用于所有元素,包含伪对象::beforeand::after
继承性
动画性
计算值指定值
媒体交互

实例

given the following animation:
@keyframes slidein {
 from { transform: scalex(0); }
 to { transform: scalex(1); }
}
animation: 3s ease-in 1s 2 reverse both paused slidein;
animation: 3s linear 1s slidein;
animation: 3s slidein;
//JS window.addeventlistener('load', function () { var animation = array.from(document.queryselectorall('.animation')); var button = array.from(document.queryselectorall('button')); function togglebutton (btn, type) { btn.classlist.remove('play', 'pause', 'restart'); btn.classlist.add(type); btn.title = type.touppercase(type); } function playpause (i) { var btn = button[i]; var anim = animation[i]; if (btn.classlist.contains('play')) { anim.style.animationplaystate = 'running'; togglebutton(btn, 'pause'); } else if (btn.classlist.contains('pause')) { anim.style.animationplaystate = 'paused'; togglebutton(btn, 'play'); } else { anim.classlist.remove('a' + (i + 1)); settimeout(function () { togglebutton(btn, i === 0 ? 'play' : 'pause'); anim.style.animationplaystate = ''; anim.classlist.add('a' + (i + 1)); } , 100) } } animation.foreach(function (node, index) { node.addeventlistener('animationstart', function () { togglebutton(button[index], 'pause'); } ); node.addeventlistener('animationend', function () { togglebutton(button[index], 'restart'); } ); } ); button.foreach(function (btn, index) { btn.addeventlistener('click', function () { playpause(index); } ); } ); } )
listening for dispatches
//CSS .polling_message { color: white; float: left; margin-right: 2%; } .view_port { background-color: black; height: 25px; width: 100%; overflow: hidden; } .cylon_eye { background-color: red; background-image: linear-gradient(to right, rgba(0, 0, 0, .9) 25%, rgba(0, 0, 0, .1) 50%, rgba(0, 0, 0, .9) 75%); color: white; height: 100%; width: 20%; -webkit-animation: 4s linear 0s infinite alternate move_eye; animation: 4s linear 0s infinite alternate move_eye; } @-webkit-keyframes move_eye { from { margin-left: -20%; } to { margin-left: 100%; } } @keyframes move_eye { from { margin-left: -20%; } to { margin-left: 100%; } }

潜在的问题

眨眼和闪烁的动画对于有认知问题的人来说是有问题的,比如注意力缺陷多动障碍(ADHD)。此外,某些动画效果可以触发前庭神经紊乱、癫痫、偏头痛和暗点敏感性。

考虑提供一种暂停或禁用动画的机制,以及使用Reduced Motion Media Query(简约运动媒体查询),为那些表示不喜欢动画的用户创建一个良好的体验。

div
{
	width:100px;
	height:100px;
	background:red;
	position:relative;
	animation:demp 5s infinite;
	-webkit-animation:demo 5s infinite;
}
@keyframesdemo
{
	from{left:0px;}
	to{left:450px;}
}
@-webkit-keyframes demo
{
	from{left:0px;}
	to{left:450px;}
} 

animation - 动画特效 - css 动画

效果图:

注意:Internet Explorer 9 及更早IE版本不支持 animation 属性。

鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com

免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)

图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)