translate(x,y) 定義 2D 轉換。
scale(x,y) 定義 2D 縮放轉換
rotate(angle) 定義 2D 旋轉,在參數中規定角度。css
translate定義元素在空間中的移動。對於x方向來講,向右移動,取值爲正,對於y方向來講,向下移動爲正值。
scale定義元素在空間中的縮放比例。默認是基於元素的中心爲來縮放。
rotate定義元素在空間中的旋轉。之前初中學課本中把逆時針旋轉造成的角度叫作正角,把順時針旋轉的角度叫作負角。可是在css變換中,x軸的方向是從左到右的,y軸的方向是從上到下,與課本中的座標方向相反,因此旋轉角度的正負定義與之前學過的定義正好相反即順時針爲正,逆時針爲負。css3
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-modeweb
animation-fill-mode
該屬性主要用來設置動畫在開始(設置延遲屬性的狀況下)和結束的狀態下須要顯示的效果。ide
none:動畫完成以後回到動畫沒開始時的狀態。
forwards:當動畫完成時,元素的樣式將保持keyframes最後一個關鍵幀中定義的樣式。
backwards:在 animation-delay屬性所指定的時間內,元素的樣式將設置爲keyframes中設置的第一幀的樣式。
both:同時設置了forwards和backwards屬性。即在動畫等待的時間內,元素的樣式爲keyframes設置的第一幀的樣式,動畫結束時,元素的樣式將保持最後一幀的樣式。函數
元素的透明度逐漸變化,同時位置也在不斷變化。以從左邊飛入爲例:工具
div{ width: 100px; height: 100px; margin:80px 0 0 200px; background-color: #4993c8; animation: fadeInLeft 1000ms ease 5000ms both ; } @keyframes fadeInLeft { 0% { opacity: 0; -webkit-transform: translate3d(-100%, 0, 0); transform: translate3d(-100%, 0, 0); } 100% { opacity: 1; -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); } }
元素進入頁面後,在元素位置附近作振幅較小的晃動。以從左邊進入爲例:動畫
div{ width: 100px; height: 100px; margin:80px 0 0 200px; background-color: #4993c8; animation: fadeInLeft 1000ms ease 5000ms both ; } @keyframes slideRight { 0% { opacity: 0; -webkit-transform: translateX(-150%); transform: translateX(-150%); } 50% { opacity: 1; -webkit-transform: translateX(8%); transform: translateX(8%); } 65% { -webkit-transform: translateX(-4%); transform: translateX(-4%); } 80% { -webkit-transform: translateX(4%); transform: translateX(4%); } 95% { -webkit-transform: translateX(-2%); transform: translateX(-2%); } 100% { -webkit-transform: translateX(0%); transform: translateX(0%); } }
透明度逐漸變化,尺寸先變大後變小,最後恢復正常尺寸
一、透明度變化
二、基於原來的尺寸縮放網站
div{ width: 100px; height: 100px; margin:80px 0 0 200px; background-color: #4993c8; animation: fadeInLeft 1000ms ease 5000ms both ; } @keyframes fadeIn { 0% { -webkit-transform: scale(0) translateZ(0); transform: scale(0) translateZ(0); opacity: 0; } 60% { -webkit-transform: scale(1.1) translateZ(0); transform: scale(1.1) translateZ(0); opacity: 1; } 80% { -webkit-transform: scale(0.9) translateZ(0); transform: scale(0.9) translateZ(0); opacity: 1; } 100% { -webkit-transform: scale(1) translateZ(0); transform: scale(1) translateZ(0); opacity: 1; } }
一、旋轉。順時針旋轉須要設置初始的旋轉角度爲負值,反之亦然。
二、透明度發生變化url
div{ width: 100px; height: 100px; margin:80px 0 0 200px; background-color: #4993c8; animation: rotateIn 1000ms ease 5000ms both ; } @-webkit-keyframes rotateIn { from { opacity: 0; -webkit-transform: rotate(-200deg); transform: rotate(-200deg); } to { opacity: 1; -webkit-transform: rotate(0deg); transform: rotate(0deg); } } // 能夠經過transform-origin屬性來設置旋轉元素的基點位置
主要經過animation的animation-iteration-count屬性來規定動畫無限次播放3d
思路1:設置動畫移動的起始位置和終點位置,同時設置animation的animation-direction屬性爲alternate,輪流反向播放動畫。
思路2:動畫運動分紅3個關鍵點,起始位置、50%位置和100%位置,100%時間點的位置與開始位置相同,不用設置animation的nimation-direction屬性
.arrow{ position: absolute; left: 50%; bottom: 20px; margin-left: -20px; width: 40px; height: 24px; background: url('../images/arrow.png') 0 0 no-repeat; background-size: 100% 100%; z-index: 999; animation:arrowing1 1000ms ease-in-out infinite alternate; // animation:arrowing2 1000ms ease-in-out infinite; } @keyframes arrowing1 { 0% { -webkit-transform: translateZ(0); transform: translateZ(0); } 100% { -webkit-transform:translate3d(0,20px,0); transform:translate3d(0,20px,0); } } @keyframes arrowing2 { 0% { -webkit-transform: translateY(-5px); transform: translateY(-5px); } 50% { -webkit-transform: translateY(10px); transform: translateY(10px); opacity: 1 } 100% { -webkit-transform: translateY(-5px); transform: translateY(-5px) } }