2013-05-12 143 views
8

查看CSS動畫以取代加載輪子中的動畫GIF。CSS動畫改變幀率

這裏有一個基本的例子http://jsfiddle.net/kFmY8/448/

#me { 
    -webkit-animation: rotation 2s infinite linear; 
} 

@-webkit-keyframes rotation { 
    from {-webkit-transform: rotate(0deg);} 
    to {-webkit-transform: rotate(360deg);} 
} 

我要改變的幀速率,使得每個週期有僅12幀。這將消除動畫的流動性,它與它所取代的動畫GIF更加匹配。

可以這樣做嗎?

回答

0

將動畫更改爲漸變的動畫,然後使用CSS變換旋轉屬性以30度間隔固定每個塊。將動畫應用於每個動畫,但延遲了.1s。

.wheel { 
    position:absolute; display:none; 
} 
.wheel li { 
    width:4px; height:11px; position:absolute; -webkit-transform-origin:3px 21px; background:#222; border-radius:4px; list-style:none; display:block; opacity:.25; box-shadow:0 0 1px rgba(255,255,255,0.9); 
} 
.wheel li:nth-child(1) { -webkit-transform:rotate(30deg); -webkit-animation:fadeshift 1.2s infinite linear 0s; } 
.wheel li:nth-child(2) { -webkit-transform:rotate(60deg); -webkit-animation:fadeshift 1.2s infinite linear 0.1s; } 
.wheel li:nth-child(3) { -webkit-transform:rotate(90deg); -webkit-animation:fadeshift 1.2s infinite linear 0.2s; } 
.wheel li:nth-child(4) { -webkit-transform:rotate(120deg); -webkit-animation:fadeshift 1.2s infinite linear 0.3s; } 
.wheel li:nth-child(5) { -webkit-transform:rotate(150deg); -webkit-animation:fadeshift 1.2s infinite linear 0.4s; } 
.wheel li:nth-child(6) { -webkit-transform:rotate(180deg); -webkit-animation:fadeshift 1.2s infinite linear 0.5s; } 
.wheel li:nth-child(7) { -webkit-transform:rotate(210deg); -webkit-animation:fadeshift 1.2s infinite linear 0.6s; } 
.wheel li:nth-child(8) { -webkit-transform:rotate(240deg); -webkit-animation:fadeshift 1.2s infinite linear 0.7s; } 
.wheel li:nth-child(9) { -webkit-transform:rotate(270deg); -webkit-animation:fadeshift 1.2s infinite linear 0.8s; } 
.wheel li:nth-child(10) { -webkit-transform:rotate(300deg); -webkit-animation:fadeshift 1.2s infinite linear 0.9s; } 
.wheel li:nth-child(11) { -webkit-transform:rotate(330deg); -webkit-animation:fadeshift 1.2s infinite linear 1s; } 
.wheel li:nth-child(12) { -webkit-transform:rotate(360deg); -webkit-animation:fadeshift 1.2s infinite linear 1.1s; } 
@-webkit-keyframes fadeshift { 
    from { opacity:1; } to { opacity:.1; } 
} 

<div class="appload wheel"><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></div> 

QED。

18

您想要使用steps()來代替linear的緩動功能。

-webkit-animation: rotation 2s infinite linear; 

到:

http://jsfiddle.net/trolleymusic/uTd3x/

我從改變你的動畫值

-webkit-animation: rotation 2s infinite steps(12); 

steps函數內部的數量將多少幀劃分動畫成。的參考

位:http://css-tricks.com/snippets/css/keyframe-animation-syntax/ - 約一半,有一個部分叫做步驟()

+0

將不是這種6fps的,而不是如圖12所示,作爲12個步驟被超過2秒分? – 2017-01-21 11:42:56

+0

是的。原始帖子每個週期需要12幀,週期爲2秒長。 – Trolleymusic 2017-04-18 10:54:33