css中的过度效果

CSS3中,我们为了添加某种效果可以从一种样式转变到另一个的时候,无需使用Flash动画或JavaScript。

1、CSS3 过渡是元素从一种样式逐渐改变为另一种的效果
要实现这一点,必须规定两项内容:
    指定要添加效果的CSS属性
    指定效果的持续时间

 

[JavaScript] 纯文本查看 复制代码

?

1

2

3

4

[/p]div{

   transition: width 2s;

   -webkit-transition: width 2s; /* Safari */

}

实例:应用于宽度属性的过渡效果,时长为 2 秒:

注意: 如果未指定的期限,transition将没有任何效果,因为默认值是0。

指定的CSS属性的值更改时效果会发生变化。一个典型CSS属性的变化是用户鼠标放在一个元素上时

 

[JavaScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

<!DOCTYPE html>

<html>

  <head>

    <meta charset="utf-8">

    <style>

     div {

      width:100px;

      height:100px;

      background:red;

      transition:width 2s;

      -webkit-transition:width 2s; /* Safari */

     }

     div:hover {

      width:300px;

     }

    </style>

  </head>

  <body>

    <p><b>注意:</b>该实例无法在 Internet Explorer 9 及更早 IE 版本上工作。</p>

    <div></div>

  </body>

</html>

 

2、多项改变

要添加多个样式的变换效果,添加的属性由逗号分隔:

 

[JavaScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<style>

   div {

    width: 100px;

    height: 100px;

    background: red;

    -webkit-transition: width 2s, height 2s, -webkit-transform 2s; /* For Safari 3.1 to 6.0 */

    transition: width 2s, height 2s, transform 2s;

   }

   div:hover {

    width: 200px;

    height: 200px;

    -webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */

    transform: rotate(180deg);

   }[/p][p=26, null, left]</style>

</head>

<body>

  <p><b>注意:</b>该实例无法在 Internet Explorer 9 及更早 IE 版本上工作。</p>

  <div>鼠标移动到 div 元素上,查看过渡效果。</div>

</body>

</html>

 

3、过渡属性

下表列出了所有的过渡属性:

属性

描述

CSS

transition

简写属性,用于在一个属性中设置四个过渡属性。

3

transition-property

规定应用过渡的 CSS 属性的名称。

3

transition-duration

定义过渡效果花费的时间。默认是 0。

3

transition-timing-function

规定过渡效果的时间曲线。默认是 "ease"。

3

transition-delay

规定过渡效果何时开始。默认是 0。

3

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<style>

div {

   width:100px;

   height:100px;

   background:red;

   transition:width 1s linear 2s;

   /* Safari */

   -webkit-transition:width 1s linear 2s;

}

div:hover {

   width:200px;

}

</style>

</head>

<body>

  <p><b>注意:</b>该实例无法在 Internet Explorer 9 及更早 IE 版本上工作。</p>

  <div></div>

  <p><b>注意:</b> 过渡效果需要等待两秒后才开始。</p>

</body>

</html>

猜你喜欢

转载自blog.csdn.net/qq_39581763/article/details/82454319