animations與transition

来源:https://www.cnblogs.com/YushinFukuhara/archive/2019/11/05/11800982.html
-Advertisement-
Play Games

transition過渡 和animation 動畫 要知道 transition過渡和animation動畫都是實現元素運動的一種方式。區別在於: transition過渡需要人為觸發,例如點擊觸發或者滑鼠懸停觸發,而animation是可以不需要人為觸發。transition功能支持從一個屬性值 ...


transition過渡 和animation 動畫

要知道 transition過渡和animation動畫都是實現元素運動的一種方式。區別在於: transition過渡需要人為觸發,例如點擊觸發或者滑鼠懸停觸發,而animation是可以不需要人為觸發。transition功能支持從一個屬性值平滑到另外一個屬性值,animations功能支持通過關鍵幀的指定來在頁面產生更複雜的動畫效果。


 

transition過渡

transition 過渡是元素從一種樣式逐漸改變為另一種的效果。

要實現這一點,必須規定兩項內容:

  • 規定您希望把效果添加到哪個 CSS 屬性上
  • 規定效果的時長

如果時長未規定,則不會有過渡效果,因為預設值是 0

過濾的屬性

  transition            簡寫屬性,用於在一個屬性中設置四個過渡屬性。

  transition-property        規定應用過渡的 CSS 屬性的名稱。

  transition-duration        定義過渡效果花費的時間。預設是 0。

  transition-timing-function   規定過渡效果的時間曲線。預設是 "ease"。

  transition-delay       規定過渡效果何時開始。預設是 0。

 

實例

div {

  transition-property: width;

  transition-duration: 1s;

  transition-timing-function: linear;

  transition-delay: 2s;

  /* Firefox 4 */

   -moz-transition-property:width;

  -moz-transition-duration:1s;

  -moz-transition-timing-function:linear;

  -moz-transition-delay:2s;

  /* Safari 和 Chrome */

  -webkit-transition-property:width;

  -webkit-transition-duration:1s;

  -webkit-transition-timing-function:linear;

  -webkit-transition-delay:2s;

  /* Opera */

  -o-transition-property:width;

  -o-transition-duration:1s;

  -o-transition-timing-function:linear;

  -o-transition-delay:2s;

}

 

 

 

animation 動畫

當您在 @keyframes 中創建動畫時,需要把它捆綁到某個選擇器,否則不會產生動畫效果。

動畫屬性

  • 規定動畫的名稱
  • 規定動畫的時長

您必須定義動畫的名稱和時長。如果忽略時長,則動畫不會允許,因為預設值是 0。

animation動畫屬性

  animation         所有動畫屬性的簡寫屬性,除了 animation-play-state 屬性。

  animation-name      規定 @keyframes 動畫的名稱。

  animation-duration     規定動畫完成一個周期所花費的秒或毫秒。預設是 0。

  animation-timing-function  規定動畫的速度曲線。預設是 "ease"。

  animation-delay         規定動畫何時開始。預設是 0。

  animation-iteration-count  規定動畫被播放的次數。預設是 1。

  animation-direction      規定動畫是否在下一周期逆向地播放。預設是 "normal"。

  animation-play-state    規定動畫是否正在運行或暫停。預設是 "running"。

  animation-fill-mode      規定對象動畫時間之外的狀態。

 


實例

div
{

animation: myfirst 5s;

-moz-animation: myfirst 5s;/* Firefox */

-webkit-animation: myfirst 5s;/* Safari 和 Chrome */

-o-animation: myfirst 5s;/* Opera */

}


@keyframes myfirst

{

0% {background: red;}

25% {background: yellow;}

50% {background: blue;}

100% {background: green;}

}

@-moz-keyframes myfirst /* Firefox */

{

0% {background: red;}

25% {background: yellow;}

50% {background: blue;}

100% {background: green;}

}

@-webkit-keyframes myfirst /* Safari 和 Chrome */

{

0% {background: red;}

25% {background: yellow;}

50% {background: blue;}

100% {background: green;}

}

@-o-keyframes myfirst /* Opera */

{

0% {background: red;}

25% {background: yellow;}

50% {background: blue;}

100% {background: green;}

}

 

實踐源碼

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tree-table</title>
<style>
/*transition的動畫*/
.t1{
width:100px;
height:100px;
transition:background-color 2s,width 2s,height 2s;
background-color:yellow;
}
.t1:hover{
width:200px;
height:200px;
transition:background-color 2s,width 2s,height 2s;
background-color:red;
}

/*animation的動畫*/
.a1{
width:100px;
height:100px;
background-color:yellow;
margin-top:20px;
animation:m 5s infinite;
position:relative;
}

@keyframes m{
0% {background: red; left:0px; top:0px;}
25% {background: yellow; left:200px; top:0px;}
50% {background: blue; left:200px; top:200px;}
75% {background: green; left:0px; top:200px;}
100% {background: red; left:0px; top:0px;}
}
</style>
</head>
<body>
<!-- transition的動畫 -->
<h2>transition的動畫 滑鼠觸發</h2>
<div class="t1"></div>
<!-- animation的動畫 -->
<h2>animation的動畫</h2>
<div class="a1"></div>
</body>
<script>
</script>
</html>

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) fin... ...
  • @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (B ...
  • 實現列表動畫 ...
  • 鉤子函數實現小球彈落 ...
  • 不使用動畫 使用過渡類名實現動畫 修改vue的首碼 第三方類實現動畫 需引入css文件:`` ...
  • 案例改進 vue resource全局配置: 全局啟用 emulateJSON 選項 ...
  • 負邊距與雙飛翼佈局 負邊距 當設置top和left方向的負邊距時,元素本身向指定方向移動。當設置bottom和right方向的負邊距時,元素本身不移動,處於元素後方的元素向前流動,覆蓋其上。 聖杯佈局 聖杯佈局是一個三欄佈局,左右定寬,中間自適應。 HTML佈局 得到如圖所示的三個div。 CSS設 ...
  • 先介紹下這個問題的由來: 上午其他項目組人員在rtx上問,求幫忙解決ie8相容性問題。 然後快到飯點,知道這個bug肯定不是那麼好解決,肯定不能耽誤吃飯時間。 果斷說,下午來弄。 下午3點開始去看這個bug。 具體問題就是:點擊修改按鈕報了缺少':',186行錯誤。 看了下他的代碼186行,是空白行 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 在我們開發過程中基本上不可或缺的用到一些敏感機密數據,比如SQL伺服器的連接串或者是OAuth2的Secret等,這些敏感數據在代碼中是不太安全的,我們不應該在源代碼中存儲密碼和其他的敏感數據,一種推薦的方式是通過Asp.Net Core的機密管理器。 機密管理器 在 ASP.NET Core ...
  • 新改進提供的Taurus Rpc 功能,可以簡化微服務間的調用,同時可以不用再手動輸出模塊名稱,或調用路徑,包括負載均衡,這一切,由框架實現並提供了。新的Taurus Rpc 功能,將使得服務間的調用,更加輕鬆、簡約、高效。 ...
  • 順序棧的介面程式 目錄順序棧的介面程式頭文件創建順序棧入棧出棧利用棧將10進位轉16進位數驗證 頭文件 #include <stdio.h> #include <stdbool.h> #include <stdlib.h> 創建順序棧 // 指的是順序棧中的元素的數據類型,用戶可以根據需要進行修改 ...
  • 前言 整理這個官方翻譯的系列,原因是網上大部分的 tomcat 版本比較舊,此版本為 v11 最新的版本。 開源項目 從零手寫實現 tomcat minicat 別稱【嗅虎】心有猛虎,輕嗅薔薇。 系列文章 web server apache tomcat11-01-官方文檔入門介紹 web serv ...
  • C總結與剖析:關鍵字篇 -- <<C語言深度解剖>> 目錄C總結與剖析:關鍵字篇 -- <<C語言深度解剖>>程式的本質:二進位文件變數1.變數:記憶體上的某個位置開闢的空間2.變數的初始化3.為什麼要有變數4.局部變數與全局變數5.變數的大小由類型決定6.任何一個變數,記憶體賦值都是從低地址開始往高地 ...
  • 如果讓你來做一個有狀態流式應用的故障恢復,你會如何來做呢? 單機和多機會遇到什麼不同的問題? Flink Checkpoint 是做什麼用的?原理是什麼? ...
  • C++ 多級繼承 多級繼承是一種面向對象編程(OOP)特性,允許一個類從多個基類繼承屬性和方法。它使代碼更易於組織和維護,並促進代碼重用。 多級繼承的語法 在 C++ 中,使用 : 符號來指定繼承關係。多級繼承的語法如下: class DerivedClass : public BaseClass1 ...
  • 前言 什麼是SpringCloud? Spring Cloud 是一系列框架的有序集合,它利用 Spring Boot 的開發便利性簡化了分散式系統的開發,比如服務註冊、服務發現、網關、路由、鏈路追蹤等。Spring Cloud 並不是重覆造輪子,而是將市面上開發得比較好的模塊集成進去,進行封裝,從 ...
  • class_template 類模板和函數模板的定義和使用類似,我們已經進行了介紹。有時,有兩個或多個類,其功能是相同的,僅僅是數據類型不同。類模板用於實現類所需數據的類型參數化 template<class NameType, class AgeType> class Person { publi ...
  • 目錄system v IPC簡介共用記憶體需要用到的函數介面shmget函數--獲取對象IDshmat函數--獲得映射空間shmctl函數--釋放資源共用記憶體實現思路註意 system v IPC簡介 消息隊列、共用記憶體和信號量統稱為system v IPC(進程間通信機制),V是羅馬數字5,是UNI ...