弄清 CSS3 的 transition 和 animation

transition

transition 属性是

transition-property,

transition-duration,

transition-timing-function,

transition-delay

的简称,用于设定一个元素的两个状态,不同的状态可以用伪类,比如:hover, :active 或者是通过 javascript 动态设定。IE10+支持。

所以 transition 的初始值为:

transition-delay: 0s;
transition-duration: 0s;
transition-property: all;
transition-timing-function: ease;

用法

div {
transition: <property> <duration> <timing-function> <delay>;
}

并且有事件可以监测 transition 结束

el.addEventListener("transitionend",updateTransition,true);

//in webkit
el.addEventListener("webkitTransitionEnd",updateTransition,true);

实例

HTML

<!--  DEMO 1: Fade Block -->
<div id="fade">
move here !
</div> <div id="nudge">
mouse on me
</div> <div id="bounce">Place mouse on me i will bounce!</div> <div id="spin">Place mouse on me i won me i won me i won me i won me i won me i won me i won me i won me i won me i won me i won me i won me i won me i won me i will spin</div> <div id="accordion" class="accordion">
<a href="#first">This is first tab</a>
<div id="first"><p>Lorem ipsum </p> </div> <a href="#second">This is second tab</a>
<div id="second"><p>Lorem ipsum </p> </div> <a href="#third">This is third tab</a>
<div id="third"><p>Lorem ipsum </p> </div>
</div>

CSS

/*
DEMO 1: Fade Block
*/
div {
margin-bottom: 50px;
} #fade {
/*opacity:1;
-webkit-transition: opacity 10s liner 10s;*/
position: relative;
transition-property: font-size;
transition-duration: 0.5s;
transition-delay: 0;
font-size: 14px;
} #fade:hover {
font-size: 36px;
} /* DEMO2 */
#nudge{ -webkit-transition-property: color,
background-color,padding-left;
-webkit-transition-duration: 500ms,500ms, 500ms;
} #nudge:hover{
background-color: #efefef;
color: #333;
padding-left: 50px;
} #bounce:hover {
-webkit-animation-name:bounce;
-webkit-animation-duration:1s;
-webkit-animation-iteration-count:2;
-webkit-animation-direction:alternate
}
@-webkit-keyframes bounce {
from{margin-left:0;}
to{margin-left:250px;}
} #spin{
-webkit-transition: -webkit-transform 10s ease-in;
} #spin:hover{
-webkit-transform: rotate(36000deg);
} .accordion a{
display: block;
padding:5px 10px;
background-color:#ccc;
color:#000; /*可以去掉链接的下划线等修饰效果*/
text-decoration:none; }
.accordion a:hover{
background-color:#999;
}
.accordion div{
background-color:#cda;
color:#222;
}
.accordion div p{
padding:20px
} #accordion div{
/*先隐藏起来*/
height:0;
overflow:hidden; -webkit-transition:height 600ms ease;
} #accordion div:target{
height:110px;
}

animation

animation 属性是如下这些属性的简写

animation-name: none

animation-duration: 0s

animation-timing-function: ease

animation-delay: 0s

animation-iteration-count: 1

animation-direction: normal

animation-fill-mode: none

用法

animation:
animation-name
time(duration)
timing-function
time(delay)
animation-iteration-count( 结束之前的循环次数)
single-animation-direction
/*{
animation-direction: normal (每次从正方向开始)
animation-direction: reverse (每次从反方向开始)
animation-direction: alternate (正反往复)
}*/
single-animation-fill-mode

实例

<div class="view_port">
<div class="polling_message">
Listener for dispatches
</div>
<div class="cylon_eye">
</div>
</div>
.polling_message {
color: white;
float: left;
margin-right:2%;
}
.view_port {
background-color: black;
height: 50px;
width: 100%;
overflow: hidden;
}
.cylon_eye {
color: white;
height: 100%;
width: 80%;
background-color: red; background-image: linear-gradient(to right, rgba(0, 0, 0, 0.9) 25%, rgba(0, 0, 0, 0.1) 50%, rgba(0, 0, 0, 0.9) 75%); -webkit-animation: move_eye 4s linear 0s infinite alternate;
-moz-animation: move_eye 4s linear 0s infinite alternate;
-o-animation: move_eye 4s linear 0s infinite alternate;
animation: move_eye 4s linear 0s infinite alternate;
}
@-webkit-keyframes move_eye {
from {
margin-left:-20%;
}
to {
margin-left:100%;
}
}
@-moz-keyframes move_eye {
from {
margin-left:-20%;
}
to {
margin-left:100%;
}
}
@-o-keyframes move_eye {
from {
margin-left:-20%;
}
to {
margin-left:100%;
}
}
@keyframes move_eye {
from {
margin-left:-20%;
}
to {
margin-left:100%;
}
}

弄清 CSS3 的 transition 和 animation的更多相关文章

  1. CSS3动画 transition和animation的用法和区别

    transition和animation都是CSS3新增的特性,使用时需要加内核 浏览器 内核名称 W3C   IE  -ms-  Chrome/Safari -webkit-   Firefoc - ...

  2. 2018年1月17日总结 css3里transition 和animation 区别

    transition 和animation两个CSS3属性经常被用到实际项目中,想把它整理出来. 1.先介绍transition >>>>>  a. 在做项目中经常会遇见 ...

  3. css3,transition,animation两种动画实现区别

    我们为页面设置动画时,往往会用到transition还有animation以及transfrom属性或者用到js. 其实通常情况下,对于使用js我们更加倾向于使用css来设置动画. transfrom ...

  4. css3中transition和animation的回调处理

    弱鸡最近在准备面试,网上找了一些题,发现一些基础题也完全答不好(┬_┬)看来还是要再接再励啊w(゚Д゚)w 言归正传,今天的主题是CSS3中的动画回调处理,这里动画执行完毕后触发的事件是transit ...

  5. css3 transition 和 animation实现走马灯

    这段时间在做一个App,H5的开发.页面上有公告 以走马灯的形式显示出来. 在开始直接用的marquee标签,后来发现在ios客户端,走马灯移动不够平滑,有抖动现象. 对于有强迫症的我而言是无法忍受的 ...

  6. css3动画入门transition、animation

    css3动画 transition.animation CSS3 transition demo <!DOCTYPE html> <html> <head> < ...

  7. css3实践之图片轮播(Transform,Transition和Animation)

    楼主喜欢追求视觉上的享受,虽常以牺牲性能无法兼容为代价却也乐此不疲.本文就通过一个个的demo演示来简单了解下css3下的Transform,Transition和Animation. 本文需要实现效 ...

  8. CSS3中动画属性transform、transition和animation

    Transform:变形 在网页设计中,CSS被习惯性的理解为擅长表现静态样式,动态的元素必须借助于javascript才可以实现,而CSS3的出现改变了这一思维方式.CSS3除了增加革命性的创新功能 ...

  9. CSS3中动画属性transform、transition 和 animation

    CSS3中和动画有关的属性有三个 transform.transition 和 animation.下面来一一说明:        transform   从字面来看transform的释义为改变,使 ...

随机推荐

  1. Tomcat 学习心得

    Tomcat Server的结构图 Tomcat服务器的启动是基于一个server.xml文件的,Tomcat启动的时候首先会启动一个Server,Server里面就会启动Service,Servic ...

  2. How to create a Python dictionary with double quotes as default quote format?

    couples = [ ['jack', 'ilena'], ['arun', 'maya'], ['hari', 'aradhana'], ['bill', 'samantha']] pairs = ...

  3. Mac 使用Sublime Text 3 搭建C开发环境

    Sublime Text 3  (安装包,注册码 ,汉化包) 1)工具-编译系统-新建编译器 { "cmd" : ["gcc -o ${file_base_name} $ ...

  4. 461. Hamming Distance

    https://leetcode.com/problems/hamming-distance/ 将两个二进制数比较,输出不同位数的个数 Input: x = 1, y = 4 Output: 2 Ex ...

  5. 【转载】在HTML中插入swf文件(转)

    在HTML中插入swf文件(转) 在网页里面插入swf,再平常不过了,一般会想到如下代码: Html代码 <object classid="clsid:D27CDB6E-AE6D-11 ...

  6. 求两个数字的最大公约数-Python实现,三种方法效率比较,包含质数打印质数的方法

    今天面试,遇到面试官询求最大公约数.小学就学过的奥数题,居然忘了!只好回答分解质因数再求解! 回来果断复习下,常用方法辗转相除法和更相减损法,小学奥数都学过,很简单,就不细说了,忘了的话可以百度:ht ...

  7. Spring学习(二)

    1. AOP的思想(如何实现),AOP在哪些地方使用? 相关术语有哪些? AOP是面向切面编程,它是一种编程思想,采取横向抽取机制,取代了传统纵向继承体系重复性代码的方式 应用场景有: 记录日志 监控 ...

  8. PHP单例模式

    //1.单例模式//目的:为了控制对象的数量(只能够有一个,相当于类的计划生育)//做法//1.将类的构造函数做成私有的//2.在类里面做了一个公有的函数来造对象//3.将该函数变为静态的//4.在函 ...

  9. ThreadStart 与ParameterizedThreadStart的区别

    1) ParameterizedThreadStart与ThreadStart 1 static void Main(string[] args) { #region ParameterizedThr ...

  10. pk8和x509.pem转换成keystore

    转自:http://www.cnblogs.com/platte/p/3511814.html 一 在github上下载工具 https://github.com/getfatday/keytool- ...