CSS3 基础(006_过渡)

原始网址:http://www.w3schools.com/css/css3_transitions.asp

翻译:

CSS3 过渡(CSS3 Transitions)


CSS3 过渡

CSS3 过渡允许你在给定的持续时间之内以平缓地改变属性值(从一个值改变为另一个值)。

示例:鼠标指针悬停于下列元素之上以观察 CSS3 的过渡效果
CSS3 过渡

<!DOCTYPE html>
<html>
<head>
<style>
.animated_div {
    background: #92b901 none repeat scroll 0 0;
    border-radius: 5px;
    color: #ffffff;
    float: left;
    font-size: 15px;
    font-weight: bold;
    height: 40px;
    margin: 5px;
    opacity: 0.4;
    padding: 10px;
    position: absolute;
    transition: width 1s ease 0s, height 1s ease 0s, transform 1s ease 0s, background 1s ease 0s, font-size 1s ease 0s, opacity 1s ease 0s;
    width: 65px;
}

.animated_div:hover {
    background: #1ec7e6 none repeat scroll 0 0;
    font-size: 35px;
    height: 80px;
    opacity: 1;
    width: 130px;
}
</style>
</head>
<body>
    <div style="height: 90px;"><div class="animated_div">CSS3</div></div>
</body>
</html>

Browser Support for Transitions

表格里的数字代表对 CSS3 属性全面支持的各浏览器的第一个版本号。
数字之后跟从 -webkit--moz--o- 指定带前缀工作的第一个版本号。

属性(Property)chromeIEfirefoxsafariopera
transition26.0
4.0 -webkit-
10.016.0
4.0 -moz-
6.1
3.1 -webkit-
12.1
10.5 -o-
transition-delay26.0
4.0 -webkit-
10.016.0
4.0 -moz-
6.1
3.1 -webkit-
12.1
10.5 -o-
transition-duration26.0
4.0 -webkit-
10.016.0
4.0 -moz-
6.1
3.1 -webkit-
12.1
10.5 -o-
transition-property26.0
4.0 -webkit-
10.016.0
4.0 -moz-
6.1
3.1 -webkit-
12.1
10.5 -o-
transition-timing-function26.0
4.0 -webkit-
10.016.0
4.0 -moz-
6.1
3.1 -webkit-
12.1
10.5 -o-

如何使用 CSS3 过渡?

要创建过渡效果,你必须满足 2 个条件:

  • 你想添加效果的 CSS 属性
  • 效果的持续时间

    注意:如果持续时间部分没有被指定,将不会产生过渡效果,因为该默认值为 0

下列示例将呈现 100px * 100px 的红色 <div> 元素。该 <div> 元素还对宽度指定了过渡效果,持续时间为 2 秒:

div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: width 2s; /* Safari */
    transition: width 2s;
}

当被指定的 CSS 属性(宽)变更值的时候,过渡效果开始发生。
现在,当用户鼠标指针悬停于 <div> 元素之上的时候,让我们给予宽度属性一个新值:

div:hover {
    width: 300px;
}

CSS3 过渡

<!DOCTYPE html>
<html>
<head>
<style>
div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: width 2s; /* For Safari 3.1 to 6.0 */
    transition: width 2s;
}

div:hover {
    width: 300px;
}
</style>
</head>
<body>
    <p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
    <div></div>
    <p>Hover over the div element above, to see the transition effect.</p>
</body>
</html>

注意:当光标移出元素的时候,它将逐渐变回到原样式。


改变多个属性值

下列示例对宽、高属性均添加过渡效果,对宽度的持续时间为 2 秒,对高度的持续时间为 4 秒:

div {
    -webkit-transition: width 2s, height 4s; /* Safari */
    transition: width 2s, height 4s;
}

改变多个属性值

<!DOCTYPE html>
<html>
<head>
<style>
div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: width 2s, height 4s; /* For Safari 3.1 to 6.0 */
    transition: width 2s, height 4s;
}

div:hover {
    width: 300px;
    height: 300px;
}
</style>
</head>
<body>
    <p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
    <div></div>
    <p>Hover over the div element above, to see the transition effect.</p>
</body>
</html>

指定过渡的速度曲线

transition-timing-function 属性指定过渡效果的速度曲线。
transition-timing-function 可以有以下取值:

  • ease - 指定过渡效果为慢、快、慢的节奏(默认值)
  • linear - 指定过渡效果为匀速
  • ease-in - 指定过渡效果为慢开始
  • ease-out - 指定过渡效果为慢结束
  • ease-in-out - 指定过渡效果为慢开始、慢结束
  • cubic-bezier(n,n,n,n) - 自定义贝塞尔曲线函数值

下列示例展示了可被使用的不同速度曲线:

#div1 {transition-timing-function: linear;}
#div2 {transition-timing-function: ease;}
#div3 {transition-timing-function: ease-in;}
#div4 {transition-timing-function: ease-out;}
#div5 {transition-timing-function: ease-in-out;}

指定过渡的速度曲线

<!DOCTYPE html>
<html>
<head>
<style>
div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: width 2s; /* Safari */
    transition: width 2s;
}

/* For Safari 3.1 to 6.0 */
#div1 {
    -webkit-transition-timing-function: linear;
}

#div2 {
    -webkit-transition-timing-function: ease;
}

#div3 {
    -webkit-transition-timing-function: ease-in;
}

#div4 {
    -webkit-transition-timing-function: ease-out;
}

#div5 {
    -webkit-transition-timing-function: ease-in-out;
}

/* Standard syntax */
#div1 {
    transition-timing-function: linear;
}

#div2 {
    transition-timing-function: ease;
}

#div3 {
    transition-timing-function: ease-in;
}

#div4 {
    transition-timing-function: ease-out;
}

#div5 {
    transition-timing-function: ease-in-out;
}

div:hover {
    width: 300px;
}
</style>
</head>
<body>
    <p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
    <div id="div1">linear</div>
    <br>
    <div id="div2">ease</div>
    <br>
    <div id="div3">ease-in</div>
    <br>
    <div id="div4">ease-out</div>
    <br>
    <div id="div5">ease-in-out</div>
    <br>
    <p>Hover over the div elements above, to see the different speed curves.</p>
</body>
</html>

延迟过渡效果(Delay the Transition Effect)

transition-delay 属性指定过渡效果的延迟。
下列示例在开始之前有 1 秒延迟:

div {
    -webkit-transition-delay: 1s; /* Safari */
    transition-delay: 1s;
}

延迟过渡效果

<!DOCTYPE html>
<html>
<head>
<style>
div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: width 3s; /* Safari */
    -webkit-transition-delay: 1s; /* Safari */
    transition: width 3s;
    transition-delay: 1s;
}

div:hover {
    width: 300px;
}
</style>
</head>
<body>
    <p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
    <div></div>
    <p>Hover over the div element above, to see the transition effect.</p>
    <p><b>Note:</b> The transition effect has a 1 second delay before starting.</p>
</body>
</html>

过渡 + 变换(Transition + Transformation)

下列示例给过渡效果增加变换:

div {
    -webkit-transition: width 2s, height 2s, -webkit-transform 2s; /* Safari */
    transition: width 2s, height 2s, transform 2s;
}

过渡 + 变换

<!DOCTYPE html>
<html>
<head>
<style>
div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: width 2s, height 2s, -webkit-transform 2s;
    /* Safari */
    transition: width 2s, height 2s, transform 2s;
}

div:hover {
    width: 300px;
    height: 300px;
    -webkit-transform: rotate(180deg); /* Safari */
    transform: rotate(180deg);
}
</style>
</head>
<body>
    <p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
    <div></div>
    <p>Hover over the div element above, to see the transition effect.</p>
</body>
</html>

更多过渡示例(More Transition Examples)

CSS3 过渡属性可以被单个指定,如下:

div {
    transition-property: width;
    transition-duration: 2s;
    transition-timing-function: linear;
    transition-delay: 1s;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
    width: 100px;
    height: 100px;
    background: red;
    /* For Safari 3.1 to 6.0 */
    -webkit-transition-property: width;
    -webkit-transition-duration: 2s;
    -webkit-transition-timing-function: linear;
    -webkit-transition-delay: 1s;
    /* Standard syntax */
    transition-property: width;
    transition-duration: 2s;
    transition-timing-function: linear;
    transition-delay: 1s;
}

div:hover {
    width: 300px;
}
</style>
</head>
<body>
    <p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
    <div></div>
    <p>Hover over the div element above, to see the transition effects.</p>
    <p><b>Note:</b> The transition effect has a 1 second delay before starting.</p>
</body>
</html>

或使用简写属性 transition

div {
    transition: width 2s linear 1s;
}
<!DOCTYPE html>
<html>
<head>
<style>
div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: width 2s linear 1s; /* For Safari 3.1 to 6.0 */
    transition: width 2s linear 1s;
}

div:hover {
    width: 300px;
}
</style>
</head>
<body>
    <p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
    <div></div>
    <p>Hover over the div element above, to see the transition effect.</p>
    <p><b>Note:</b> The transition effect has a 1 second delay before starting.</p>
</body>
</html>
Stkcd [股票代码] ShortName [股票简称] Accper [统计截止日期] Typrep [报表类型编码] Indcd [行业代码] Indnme [行业名称] Source [公告来源] F060101B [净利润现金净含量] F060101C [净利润现金净含量TTM] F060201B [营业收入现金含量] F060201C [营业收入现金含量TTM] F060301B [营业收入现金净含量] F060301C [营业收入现金净含量TTM] F060401B [营业利润现金净含量] F060401C [营业利润现金净含量TTM] F060901B [筹资活动债权人现金净流量] F060901C [筹资活动债权人现金净流量TTM] F061001B [筹资活动股东现金净流量] F061001C [筹资活动股东现金净流量TTM] F061201B [折旧摊销] F061201C [折旧摊销TTM] F061301B [公司现金流1] F061302B [公司现金流2] F061301C [公司现金流TTM1] F061302C [公司现金流TTM2] F061401B [股权现金流1] F061402B [股权现金流2] F061401C [股权现金流TTM1] F061402C [股权现金流TTM2] F061501B [公司自由现金流(原有)] F061601B [股权自由现金流(原有)] F061701B [全部现金回收率] F061801B [营运指数] F061901B [资本支出与折旧摊销比] F062001B [现金适合比率] F062101B [现金再投资比率] F062201B [现金满足投资比率] F062301B [股权自由现金流] F062401B [企业自由现金流] Indcd1 [行业代码1] Indnme1 [行业名称1] 季度数据,所有沪深北上市公司的 分别包含excel、dta数据文件格式及其说明,便于不同软件工具对数据的分析应用 数据来源:基于上市公司年报及公告数据整理,或相关证券交易所、各部委、省、市数据 数据范围:基于沪深北证上市公司 A股(主板、中小企业板、创业板、科创板等)数据整理计算
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值