transition过渡 和animation 动画

要知道 transition过渡和animation动画都是实现元素运动的一种方式。区别在于: transition过渡需要人为触发,例如点击触发或者鼠标悬停触发,而animation是可以不需要人为触发。transition功能支持从一个属性值平滑到另外一个属性值,animations功能支持通过关键帧的指定来在页面产生更复杂的动画效果。


transition过渡

transition 过渡是元素从一种样式逐渐改变为另一种的效果。

要实现这一点,必须规定两项内容:

  • 规定您希望把效果添加到哪个 CSS 属性上
  • 规定效果的时长

如果时长未规定,则不会有过渡效果,因为默认值是 0

过滤的属性

  transition            简写属性,用于在一个属性中设置四个过渡属性。

  transition-property        规定应用过渡的 CSS 属性的名称。

  transition-duration        定义过渡效果花费的时间。默认是 0。

  transition-timing-function   规定过渡效果的时间曲线。默认是 "ease"。

  transition-delay       规定过渡效果何时开始。默认是 0。

实例

div {

  transition-property: width;

  transition-duration: 1s;

  transition-timing-function: linear;

  transition-delay: 2s;

  /* Firefox 4 */

   -moz-transition-property:width;

  -moz-transition-duration:1s;

  -moz-transition-timing-function:linear;

  -moz-transition-delay:2s;

  /* Safari 和 Chrome */

  -webkit-transition-property:width;

  -webkit-transition-duration:1s;

  -webkit-transition-timing-function:linear;

  -webkit-transition-delay:2s;

  /* Opera */

  -o-transition-property:width;

  -o-transition-duration:1s;

  -o-transition-timing-function:linear;

  -o-transition-delay:2s;

}

animation 动画

当您在 @keyframes 中创建动画时,需要把它捆绑到某个选择器,否则不会产生动画效果。

动画属性

  • 规定动画的名称
  • 规定动画的时长

您必须定义动画的名称和时长。如果忽略时长,则动画不会允许,因为默认值是 0。

animation动画属性

  animation         所有动画属性的简写属性,除了 animation-play-state 属性。

  animation-name      规定 @keyframes 动画的名称。

  animation-duration     规定动画完成一个周期所花费的秒或毫秒。默认是 0。

  animation-timing-function  规定动画的速度曲线。默认是 "ease"。

  animation-delay         规定动画何时开始。默认是 0。

  animation-iteration-count  规定动画被播放的次数。默认是 1。

  animation-direction      规定动画是否在下一周期逆向地播放。默认是 "normal"。

  animation-play-state    规定动画是否正在运行或暂停。默认是 "running"。

  animation-fill-mode      规定对象动画时间之外的状态。

实例

div
{ animation: myfirst 5s; -moz-animation: myfirst 5s;/* Firefox */ -webkit-animation: myfirst 5s;/* Safari 和 Chrome */ -o-animation: myfirst 5s;/* Opera */ } @keyframes myfirst { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} } @-moz-keyframes myfirst /* Firefox */ { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} } @-webkit-keyframes myfirst /* Safari 和 Chrome */ { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} } @-o-keyframes myfirst /* Opera */ { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} }

实践源码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tree-table</title>
<style>
/*transition的动画*/
.t1{
width:100px;
height:100px;
transition:background-color 2s,width 2s,height 2s;
background-color:yellow;
}
.t1:hover{
width:200px;
height:200px;
transition:background-color 2s,width 2s,height 2s;
background-color:red;
} /*animation的动画*/
.a1{
width:100px;
height:100px;
background-color:yellow;
margin-top:20px;
animation:m 5s infinite;
position:relative;
} @keyframes m{
% {background: red; left:0px; top:0px;}
% {background: yellow; left:200px; top:0px;}
% {background: blue; left:200px; top:200px;}
% {background: green; left:0px; top:200px;}
% {background: red; left:0px; top:0px;}
}
</style>
</head>
<body>
<!-- transition的动画 -->
<h2>transition的动画 鼠标触发</h2>
<div class="t1"></div>
<!-- animation的动画 -->
<h2>animation的动画</h2>
<div class="a1"></div>
</body>
<script>
</script>
</html>

animations与transition的更多相关文章

  1. Parallax

    常听说牛人都是jquery插件用得很好的人. 现在有了github,英文过关的话什么好东西下不到啊,再不用去浏览那些抄来抄去骗人看广告的垃圾网站了. 扯远点,本人有严重的熊猫眼,所以用一种叫倦眼充电棒 ...

  2. angular动画知识点以及代码样例

    原文地址 https://www.jianshu.com/p/4400174072e2 大纲 1.angular动画的相关概念 2.angular动画的绑定方式 3.angular动画代码实例 1.a ...

  3. CSS3 新特性

    ~平时喜欢逛博客,看别人的学习总结和遇到的问题解决办法,恰好最近在做书签整理,翻到了之前一个前辈移动前端的总结,所以我就按他的总结模块对自己的知识进行了梳理,不过由于都是手写的,为了方便,下面的都是平 ...

  4. CSS3 笔记四(Transforms/Transition/Animations)

    CSS3 2D Transforms Methods translate() rotate() scale() skewX() skewY() matrix() 1> translate() T ...

  5. wp8.1 Study8:页面过渡和主题动画(Page transition and Theme animations)

    一.在WP8.1中是有动画(Animation)的: 页面导航(默认为旋转式Turnstile).PointerDown/up(默认是倾斜).页面旋转.MenuFlyout出现等等 二.页面过渡(Pa ...

  6. CSS 3学习——transition 过渡

    以下内容根据官方规范翻译以及自己的理解整理. 1.介绍 这篇文档介绍能够实现隐式过渡的CSS新特性.文档中介绍的CSS新特性描述了CSS属性的值如何在给定的时间内平滑地从一个值变为另一个值. 2.过渡 ...

  7. D3中动画(transition函数)的使用

    关于transition的几个基本点: 1. transition()是针对与每个DOM element的,每个DOM element的transition并不会影响其他DOM element的tra ...

  8. Animations功能(区别于Transitions)

    CSS3实现动画: 1  Transitions:定义元素的某个属性从一个属性值平滑过渡到另一个属性值. Transitions属性的使用方法如下所示: transition: property | ...

  9. AngularJS学习--- 动画操作 (Applying Animations) ngAnimate step 12

    1.切换目录 git checkout step-12 npm start 2.效果图 这里在点击右边的缩略图时,会有一个很明显的从下向上的动画过程. 3.代码实现: step11和step12之间的 ...

随机推荐

  1. [Flink]测试用的fake温度传感器

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  2. zip unzip 压缩解压缩命令

    直接上例子: mkdir test1 touch test1/1.txt touch test1/2.txt zip -r test1.zip test1    #-r 参数是包含文件夹下的文件 un ...

  3. itest(爱测试) 4.2.0 发布,开源BUG 跟踪管理 & 敏捷测试管理软件

    itest 入选 2019 年度最受欢迎开源中国软件 开源工具的发展,离不开你我的支持,需要您投上宝贵的一票  去投票 v4.2.0下载地址 :itest下载 itest 简介:查看简介 itest ...

  4. 最长上升子序列(LIS: Longest Increasing Subsequence)

    示例: 输入: [10,9,2,5,3,7,101,18] 输出: 4 解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4. 从网上找的一段代码(我由java改为了C++版本),原作者 ...

  5. C#所有经典排序算法汇总

    1.选择排序 选择排序 class SelectionSorter     {         private int min;         public void Sort(int[] arr) ...

  6. post 登录禅道,不成功,无解中

    ]}s.get("http://localhost/zentaopms116/www/misc-checkUpdate-16dd7448451f46bb496a2099b6a9af8c.ht ...

  7. 用Python打印九九乘法表与金字塔(*)星号

    ''' 1*1=1 2*1=2 2*2=4 3*1=3 3*2=6 3*3=9 4*1=4 4*2=8 4*3=12 4*4=16 5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 ...

  8. 《Vue 进阶系列之响应式原理及实现》

    https://www.bilibili.com/video/av51444410/?p=5 https://github.com/amandakelake/blog/issues/63 https: ...

  9. ICCV2019《KPConv: Flexible and Deformable Convolution for Point Clouds》

    针对semantic3D数据集: 1.数据集准备: Semantic3D dataset can be found <a href="http://www.semantic3d.net ...

  10. Ubuntu16.04 UltraEdit 安装&破解&使用

    (1)下载:登录到官网(http://www.ultraedit.com/downloads/uex.html)选在对应的版本进行下载. (2)安装: (使用命令行方式安装)在本地路径进行安装:sud ...