CSS3 @keyframes animate

news/2024/7/3 18:23:10

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1.@keyframes定义和用法

通过 @keyframes 规则,您能够创建动画。

创建动画的原理是,将一套 CSS 样式逐渐变化为另一套样式。

在动画过程中,您能够多次改变这套 CSS 样式。

以百分比来规定改变发生的时间,或者通过关键词 "from" 和 "to",等价于 0% 和 100%。

0% 是动画的开始时间,100% 动画的结束时间。

为了获得最佳的浏览器支持,您应该始终定义 0% 和 100% 选择器。

注释:请使用动画属性来控制动画的外观,同时将动画与选择器绑定。

2.@keyframes语法

@keyframes animationname {keyframes-selector {css-styles;}}

3.w3c上面的案例,多个样式的改变

<!DOCTYPE html>
<html>
<head>
<style> 
div
{
width:100px;
height:100px;
background:red;
position:relative;
animation:mymove 5s infinite;
-moz-animation:mymove 5s infinite; /* Firefox */
-webkit-animation:mymove 5s infinite; /* Safari and Chrome */
-o-animation:mymove 5s infinite; /* Opera */
}@keyframes mymove
{
0%   {top:0px; background:red; width:100px;}
100% {top:200px; background:yellow; width:300px;}
}@-moz-keyframes mymove /* Firefox */
{
0%   {top:0px; background:red; width:100px;}
100% {top:200px; background:yellow; width:300px;}
}@-webkit-keyframes mymove /* Safari and Chrome */
{
0%   {top:0px; background:red; width:100px;}
100% {top:200px; background:yellow; width:300px;}
}@-o-keyframes mymove /* Opera */
{
0%   {top:0px; background:red; width:100px;}
100% {top:200px; background:yellow; width:300px;}
}
</style>
</head>
<body><p><b>注释:</b>本例在 Internet Explorer 中无效。</p><div></div></body>
</html>
CSS3的animation类似于transition属性,他们都是随着时间改变元素的属性值。他们主要区别是transition需要触发一个事件 (hover事件或click事件等)才会随时间改变其css属性;而animation在不需要触发任何事件的情况下也可以显式的随着时间变化来改变元 素css的属性值,从而达到一种动画的效果。这样我们就可以直接在一个元素中调用animation的动画属性,基于这一点,css3的 animation就需要明确的动画属性值,我们需要keyframes来定义不同时间的css属性值,达到元素在不同时间 段变化的效果。

给一个元素调用animation属性

.demo1 {width: 50px;height: 50px;margin-left: 100px;background: blue;-webkit-animation-name:'wobble';/*动画属性名,也就是我们前面keyframes定义的动画名*/-webkit-animation-duration: 10s;/*动画持续时间*/-webkit-animation-timing-function: ease-in-out; /*动画频率,和transition-timing-function是一样的*/-webkit-animation-delay: 2s;/*动画延迟时间*/-webkit-animation-iteration-count: 10;/*定义循环资料,infinite为无限次*/-webkit-animation-direction: alternate;/*定义动画方式*/}

===========================

自用:

/*定义旋转*/

@-webkit-keyframes rock{0%{ transform:rotate(0deg) }10%{ transform:rotate(3deg) }20%{ transform:rotate(-3deg) }30%{ transform:rotate(2deg) }40%{ transform:rotate(-2deg) }50%{ transform:rotate(1deg) }60%{ transform:rotate(-1deg) }70%{ transform:rotate(0deg) }100%{ transform:rotate(0deg) }}

/**给需要抖动选中的元素加上动画*/

.c_zongzi_box_rock{-webkit-animation:rock 2s infinite;}

infinite是无限的动画的意思  rock定义的-webkit-keyframes的名字,2s是动画的时间

transform-origin是动画变换的基点(参照点)


1、top left | left top 等价于 0 0 | 0% 0%

2、top | top center | center top 等价于 50% 0

3、right top | top right 等价于 100% 0

4、left | left center | center left 等价于 0 50% | 0% 50%

5、center | center center 等价于 50% 50%(默认值)

6、right | right center | center right 等价于 100% 50%

7、bottom left | left bottom 等价于 0 100% | 0% 100%

8、bottom | bottom center | center bottom 等价于 50% 100%

9、bottom right | right bottom 等价于 100% 100%

其中 left,center right是水平方向取值,对应的百分值为left=0%;center=50%;right=100%而top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%;如果只取一个值,表示垂直方向值不变


转载于:https://my.oschina.net/leonaLily/blog/488745


http://lihuaxi.xjx100.cn/news/244643.html

相关文章

页面日期格式化

1.引用<script type"text/javascript" src"/js/xdate.js?version0.001"></script> 2.在页面加载的时候格式化 Date.prototype.Format function (fmt) { var o { "M": this.getMonth() 1, //月份 …

GDB 调试 Mysql 实战(二)GDB 调试打印

背景 在 https://mengkang.net/1328.html 实验中&#xff0c;我们通过optimizer_trace发现group by会使用intermediate_tmp_table&#xff0c;而且里面的的row_length是20&#xff0c;抱着"打破砂锅问到底"的求学精神&#xff0c;所以想通过 gdb 调试源码的方式看这个…

联调这夜,我把同事打了...

体验地址&#xff1a; https://www.eolink.com/?utm\_sourcew2507

在列表显示某个内容,但数据表没有这个字段

1.需求&#xff1a;在出房合同编辑页面添加业务类型内容显示 思路&#xff1a;根据房源编号查询公司房源信息表&#xff0c;获取业务类型&#xff0c;再设置进去 查询性能比较&#xff1a; 1&#xff09; for (HbContractOut entity : page.getContent()) { // 根据房源编号…

FastDFS之Linux下搭建

1.软件环境 CentOS6.5 FastDFS v5.05 libfastcommon- - master.zip&#xff08;是从 FastDFS 和 FastDHT 中提取出来的公共 C 函数库&#xff09; fastdfs- - nginx- - module_v1.16.tar.gz nginx- - 1.6.2.tar.gz fastdfs_client_java._v1.25.tar.gz 2.FastDFS集群规划 描述 …

flex版的流程设计器

第一章 介绍 1.1 编写目的 介绍流程设计软件并且简单附上使用说明。因为还不是很完善&#xff0c;所以希望大家能多提出自己的意见的见解。 1.2 基本结构 1.3 使用技术 主要使用flex技术做前端的页面&#xff0c;后端使用jbpm4.4做为流程引擎。 第二章 操作 2.1 完整界面 还在不…

比Postman好用20倍,目测要火!

最近国产API管理工具卷起来了&#xff0c;甚至发生了公开踩踏事件&#xff0c;但最后还是要回归产品&#xff0c;产品好才真的好。给大家推荐Eolink&#xff0c;低调又强大。Eolink是结合了 API 设计、文档管理、自动化测试、监控、研发管理和团队协作的一站式 API 生产平台&am…

解决js中数字相减为负数的情况

function loadSumInfo() { $.get(sumInfo, { houseBillNo : $(#houseBillNo).val() }, function(result) { var a result.totalAmt - result.approvedAmt - result.processAmt ; var s String.format(总金额:{0}, 支付中:{1}, 已支付:{2}, 待…