在HTML中實現動畫的方法

來源:互聯網
上載者:User

標籤:動畫   html   animation   opacity   


                  Animation功能中實現動畫的方法

方法

屬性值的變化速度

linear

在動畫開始與結束時以同樣速度驚醒改變

ease-in

動畫開始時速度很慢,然後速度沿曲線值進行加快

ease-out

動畫開始時速度很快,然後速度沿曲線值進行放慢

ease

動畫開始時速度很慢,然後速度沿曲線值進行加快,然後再沿曲線值進行放慢

ease-in-out

動畫開始時速度很慢,然後速度沿曲線值進行加快,然後再沿曲線值進行放慢

                 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML1.0 Transitional//EN”

“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<htmlxmlns=“http://www.w3.org/1999/xhtml”>

<head>

<meta http-equiv=“Content-Type”content=“text/html; charset=gb2312”/>

<title>實現動畫的各種方法的比較樣本</title>

</head>

<styletype=“text/css”>

@keyframesmycolor{

            0%{

                        width:100px;

                        height:100px;

            }

            100%{

                        width:500px;

                        height:500px;

            }

}

div{

            background-color:red;

            width:500px;

            height:500px;

            animation-name:mycolor;

            animation-duration:5s;

            animation-timing-function:ease-out;

}

</style>

<body>

<div>

</div>

</body>

</html>

通過以上代碼我們可以看出Animations功能中各種實現的方法的區別,該樣本中有一個div元素,頁面開啟時,該div元素在5秒內從長100px、寬100px擴大到長500px、寬500px,通過改變Animation-timing-function屬性的屬性值,然後觀察div元素額長度和寬度再整個動畫中的變化速度,可以看出實現動畫的各種方法之間的區別。

                  最後介紹下如何使用animation功能來實現網頁設計中的一種經常使用的動畫效果——網頁的淡入效果。通過再開始幀與結束幀中改變頁面的opacity屬性的屬性值來實現頁面淡入的效果。代碼如下:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML1.0 Transitional//EN”

“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<htmlxmlns=“http://www.w3.org/1999/xhtml”>

<head>

<meta http-equiv=“Content-Type”content=“text/html; charset=gb2312”/>

<title>實現網頁淡入的效果樣本</title>

</head>

<styletype=“text/css”>

@keyframesfadein{

            0%{

                        opacity:0;

                        background-color:white;

            }

            100%{

                        opacity:1;

                        background-color:white;

            }

}

</style>

<body>

樣本文字

</body>

</html>

歡迎加入技術QQ群:364595326


在HTML中實現動畫的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.