当css属性改变的时候,控制animation的速度,让属性的变化发生在一段时间之内,而不是立即生效。

语法

transition: <property> <duration> <timing-function> <delay>;

property:css属性的name, 支持的属性列表

duration:持续时间

timing-function:运动曲线

一个折叠菜单例子:

 <style type="text/css">
ul, li{
list-style:none;
float: left;
}
ul.menu {
overflow: hidden;
width: 50px;
height: 50px;
}
ul.fold {
width: 0px;
height: 0px;
transition: width 1s, height 1s;
-webkit-transition: width 1s, height 1s;
-moz-transition: width 1s, height 1s;
-o-transition: width 1s, height 1s;
}
ul.unfold {
width: 50px;
height: 50px;
background-color: #fff;
transition: width 1s, height 1s;
-webkit-transition: width 1s, height 1s;
-moz-transition: width 1s, height 1s;
-o-transition: width 1s, height 1s;
}
</style

css

html:

 <ul class="menu unfold" id="menu1">
<li>11111111</li>
<li>22222222</li>
</ul>

js:

 var v1 = document.getElementById("menu1");
function flod(){
className = v1.className;
v1.className = "menu" + (/\s+fold/.test(className) ? " unfold" : " fold");
}
v1.addEventListener("click", flod, false);

检测transition完成

transition完成后transitionend事件将被触发,如果transition还没有完成就被abort,将不会触发transitioned事件

 v1.addEventListener('transitionend', function(e){
alert(e.propertyName + "|" + e.elapsedTime);
});

js

在webkit中事件名称是webkitTransitionEnd,可以查看兼容列表

transition让js function过度更平滑

p {
padding-left: 60px;
} #foo {
border-radius: 50px;
width: 50px;
height: 50px;
background: #c00;
position: absolute;
top:;
left:;
-webkit-transition: all 1s;
transition: all 1s;
}

Css

html:

<p>Click anywhere to move the ball</p>
<div id="foo"></div>

js:

var f = document.getElementById('foo');
var info = document.getElementById('eventInfo');
document.addEventListener('click', function(ev){
f.style.left = (ev.clientX-25)+'px';
f.style.top = (ev.clientY-25)+'px';
},false);

当鼠标点击页面的时候,红色的圆会在1s内运动到当前位置。

浏览器兼容

Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
-webkit-transition -moz-transition 10 -o-transition -webkit-transition

webkitTransitionEnd

4.0 (2.0) 10 10  oTransitionEnd
12  otransitionend
12.10   transitionend
webkitTransitionEnd

最新文章

  1. pro生成sln
  2. sql where 1=1
  3. 【转载】HBase基本概念和hbase shell常用命令用法
  4. Android提高21篇之二:SurfaceView的基本使用方法
  5. Ubuntu下添加Eclipse快捷方式
  6. 压缩代码加速ecshop程序页面加载速度
  7. 如何清除xcode里面的mobileprovision文件
  8. property、synthesize、id
  9. oracle11g dataguard 完全手册(转)
  10. Loadrunner11.0调用Jar包
  11. Android For JNI(一)——JNI的概念以及C语言开发工具dev-c++,编写你的第一个C语言程序,使用C启动JAVA程序
  12. BZOJ_1827_[Usaco2010 Mar]gather 奶牛大集会_树形DP
  13. tomcat设置开机自动启动
  14. php urlencode vs java URLEncoder.encode
  15. 访问WEB-INF下的jsp页面
  16. 用python生成器实现杨辉三角
  17. Nexus3 仓库搭建(基于Docker)
  18. 高斯混合模型(理论+opencv实现)
  19. eclipse 中文件引用报错不能编译,但引用文件确实存在
  20. WebGL学习笔记七点一

热门文章

  1. 【转】使用ThinkPHP必须掌握的调试方法
  2. linux视频学习3(linux安装,shell,tcp/ip协议,网络配置)
  3. java数据结构之链表的实现
  4. g++ 编译c文件
  5. UVA 10200 Prime Time (打表)
  6. launchMode 和 onNewIntent 关系 任务栈知识.
  7. 基于ATmgea8单片机设计的加热控制系统(转)
  8. ural1701 Ostap and Partners
  9. 兼容性,float
  10. mkconfig文件解析