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