自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

CSS(Cascading Style Sheets)樣式更改——過渡、動畫

開發(fā) 前端
這篇文章我們來介紹下CSS樣式更改中的過渡、動畫基礎(chǔ)用法。

[[347721]]

前言
這篇文章我們來介紹下CSS樣式更改中的過渡、動畫基礎(chǔ)用法。

1.過渡
元素從一種樣式逐漸改變?yōu)榱硪环N的樣式 。

  1. div 
  2. transition: width 1s; 
  3. -moz-transition: width 1s;  /* Firefox 4 */ 
  4. -webkit-transition: width 1s;  /* Safari 和 Chrome */ 
  5. -o-transition: width 1s;  /* Opera */ 
  6. transition-property:應(yīng)用過渡的Css屬性的名稱 比如寬度width 
  7. transition-duration:過渡效果花費的時間   比如1s 
  8. transition-timing-function:渡效果的時間曲線 如下所示: 
  9. linear 勻速 
  10. ease 先慢后快 
  11. ease-in 慢速開始 
  12. ease-out 慢速結(jié)束 
  13. ease-in-out 慢速開始和結(jié)束 
  14. cubic-bezier(n,n,n,n) 在cubic-bezie 函數(shù)中定義自己的值,可能的值是0至1之間的數(shù)值 
  15. transition-delay:過渡效果何時開始 如1s 

2.動畫 Animation
1).首先定義@keyframes 規(guī)則

  1. @keyframes my 
  2. from {background: red;} 
  3. to {background: yellow;} 
  4.  
  5. @-moz-keyframes my /* Firefox */ 
  6. from {background: red;} 
  7. to {background: yellow;} 
  8.  
  9. @-webkit-keyframes my /* Safari 和 Chrome */ 
  10. from {background: red;} 
  11. to {background: yellow;} 
  12.  
  13. @-o-keyframes my /* Opera */ 
  14. from {background: red;} 
  15. to {background: yellow;} 

為了豐富元素的變化過程,你可以把from to改為百分比的樣子:

  1. @keyframes my 
  2. 0%   {background: red;} 
  3. 25%  {background: yellow;} 
  4. 50%  {background: blue;} 
  5. 100% {background: green;} 
  6.  
  7. @-moz-keyframes my /* Firefox */ 
  8. 0%   {background: red;} 
  9. 25%  {background: yellow;} 
  10. 50%  {background: blue;} 
  11. 100% {background: green;} 
  12.  
  13. @-webkit-keyframes my /* Safari 和 Chrome */ 
  14. 0%   {background: red;} 
  15. 25%  {background: yellow;} 
  16. 50%  {background: blue;} 
  17. 100% {background: green;} 
  18.  
  19. @-o-keyframes my /* Opera */ 
  20. 0%   {background: red;} 
  21. 25%  {background: yellow;} 
  22. 50%  {background: blue;} 
  23. 100% {background: green;} 

定義好了,接下來我們就可以啟動我們的動畫了。

2).animation啟動動畫效果

  1. div 
  2. animation-name: my; 
  3. animation-duration: 5s; 
  4. animation-timing-function: linear; 
  5. animation-delay: 2s; 
  6. animation-iteration-count: infinite; 
  7. animation-direction: alternate; 
  8. animation-play-state: running; 
  9. /* Firefox: */ 
  10. -moz-animation-name: my; 
  11. -moz-animation-duration: 5s; 
  12. -moz-animation-timing-function: linear; 
  13. -moz-animation-delay: 2s; 
  14. -moz-animation-iteration-count: infinite; 
  15. -moz-animation-direction: alternate; 
  16. -moz-animation-play-state: running; 
  17. /* Safari 和 Chrome: */ 
  18. -webkit-animation-name: my; 
  19. -webkit-animation-duration: 5s; 
  20. -webkit-animation-timing-function: linear; 
  21. -webkit-animation-delay: 2s; 
  22. -webkit-animation-iteration-count: infinite; 
  23. -webkit-animation-direction: alternate; 
  24. -webkit-animation-play-state: running; 
  25. /* Opera: */ 
  26. -o-animation-name: my; 
  27. -o-animation-duration: 5s; 
  28. -o-animation-timing-function: linear; 
  29. -o-animation-delay: 2s; 
  30. -o-animation-iteration-count: infinite; 
  31. -o-animation-direction: alternate; 
  32. -o-animation-play-state: running; 
  33.  
  34. animation-name                   選擇器的 keyframes 的名稱 
  35. animation-duration               動畫所花費的時間 
  36. animation-timing-function        勻速播放動畫 
  37. animation-delay           動畫過多久開始 
  38. animation-iteration-count        播放動畫次數(shù) 
  39. animation-direction       是否在下一周期逆向地播放 normal 正常播放  alternate 輪流反向播放 
  40. animation-play-state             暫停動畫  paused 動畫已暫停  running 動畫正在播放 
  41. animation-fill-mode 
  42. none         不填充 
  43. forwards     當(dāng)動畫完成后,保持最后一個屬性值 
  44. backwards     在animation-delay 所指定的一段時間內(nèi),在動畫顯示之前,應(yīng)用開始屬性值 
  45. both        向前和向后填充模式都被應(yīng)用。 

參考文檔:W3C官方文檔(CSS篇)

總結(jié)
這篇文章主要介紹了CSS樣式更改篇中的過度和動漫基礎(chǔ)知識,希望讓大家對CSS樣式更改有個簡單的認(rèn)識和了解。

責(zé)任編輯:姜華 來源: IT共享之家
相關(guān)推薦

2020-10-23 08:51:55

CSS

2020-10-26 13:40:00

CascadingSt

2010-09-14 15:04:42

list-styleCSS

2023-02-06 09:31:17

CSSJS 動態(tài)

2024-09-23 09:20:02

calc-sizeCSS前端

2024-03-28 09:11:24

CSS3TransitionCSS屬性

2021-05-21 07:41:15

Vue 過渡動畫

2023-04-14 16:45:21

CSS前端CSS3

2013-01-30 15:59:29

adobeCSS3HTML5

2017-07-20 11:11:39

前端CSS書寫規(guī)范

2023-11-20 09:27:28

CSS前端

2022-03-30 14:34:21

鴻蒙HarmonyOScss

2009-04-08 10:51:59

Windows Emb

2022-12-28 08:16:30

CSS新規(guī)范樣式

2010-09-13 13:44:35

CSS表格CSS表單

2011-07-29 14:55:25

iPhone開發(fā) 動畫過渡

2015-08-03 11:42:27

Swift漢堡式過度動畫

2024-03-22 12:22:50

Vue前端

2025-01-10 08:46:09

2023-07-14 07:52:37

CSS優(yōu)先級Design
點贊
收藏

51CTO技術(shù)棧公眾號