CSS3 : transition 属性

CSS3的 transition 属性用于状态过度效果!

1、语法:

 transition: property duration timing-function delay;
-moz-transition: property duration timing-function delay;
-webkit-transition: property duration timing-function delay;
-o-transition: property duration timing-function delay;

上以语法兼容各浏览器。

transition:
规定设置过渡效果的 CSS 属性的名称
过渡效果需要多少秒
规定速度效果的速度曲线
定义过渡效果何时开始

2、transition含有四个部份设置,各部份设置如下:

a) property :规定设置过渡效果的 CSS 属性的名称,可选值如下:

none   没有属性会获得过渡效果。
all 【默认值】所有属性都将获得过渡效果。
property 定义应用过渡效果的 CSS 属性名称列表,列表以逗号分隔,比如: width,height

比如: transition: width 3s; 只让宽度产生动画过渡效果,其它属性不产生效果。

b) duration:规定完成过渡效果需要多少秒或毫秒,比如:transition: all 3s; 表示3秒完成过渡效果。

c) timing-function :规定速度效果的速度曲线,可选值如下:

linear 规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))。
ease 规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。
ease-in 规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。
ease-out 规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))。
ease-in-out 规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1))。
cubic-bezier(n,n,n,n) 在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。  

d) delay:定义过渡效果何时开始,比如: transition: width 3s linear 5s;

以下是一代简易代码演示:

 <!doctype html>
<html>
<head>
<script src="js/jquery.js"></script>
<style>
.a {
width:100%;
height:200px;
transition:all 3s ease-in;
background:#03F;
}
.c {
width:300px;
}
.a:hover {
height:400px;
}
</style>
</head> <body>
<div class="a">
</div> <p>单击页面,使宽度缩小</p>
<p>移到红色区域,使高度变大</p>
<script>
$(document).click(function(){
$('.a').addClass('c');
});
</script>
</body>
</html>
上一篇:[JZOJ6075]【GDOI2019模拟2019.3.20】桥【DP】【线段树】


下一篇:[jzoj 6080] [GDOI2019模拟2019.3.23] IOer 解题报告 (数学构造)