2014-09-11 62 views
2

是否可以減少代碼以生成一組可以處理各種瀏覽器前綴的mixin?@keyframes將不同的瀏覽器版本合併爲一個

試圖減少代碼長度使用更混入

所以不是

@-moz-keyframes orbit { 
    0% { 
     opacity: 1; 
     z-index:99; 
     -moz-transform: rotate(180deg); 
     -moz-animation-timing-function: ease-out; 
    } 
} 

@-ms-keyframes orbit { 
    0% { 
     opacity: 1; 
     z-index:99; 
     -ms-transform: rotate(180deg); 
     -ms-animation-timing-function: ease-out; 
    } 
} 


@-o-keyframes orbit { 
    0% { 
     opacity: 1; 
     z-index:99; 
     -o-transform: rotate(180deg); 
     -o-animation-timing-function: ease-out; 
    } 
} 

@-webkit-keyframes orbit { 
    0% { 
     opacity: 1; 
     z-index:99; 
     -webkit-transform: rotate(180deg); 
     -webkit-animation-timing-function: ease-out; 
    } 
} 

,我們有更多的東西一樣嗎?

@keyframes orbit { 
    0% { 
     opacity: 1; 
     z-index:99; 
     -moz-transform: rotate(180deg); 
     -moz-animation-timing-function: ease-out; 

     -o-transform: rotate(180deg); 
     -o-animation-timing-function: ease-out; 

     -ms-transform: rotate(180deg); 
     -ms-animation-timing-function: ease-out; 

     -webkit-transform: rotate(180deg); 
     -webkit-animation-timing-function: ease-out; 

     transform: rotate(180deg); 
     animation-timing-function: ease-out; 
    } 
} 

回答

4

在SASS,你可以使用這個模板:

@mixin keyframes($animation-name) { 
    @-webkit-keyframes $animation-name { 
    @content; 
    } 
    @-moz-keyframes $animation-name { 
    @content; 
    } 
    @keyframes $animation-name { 
    @content; 
    } 
} 

它應該讓你開始!

+0

http://jsfiddle.net/LsMZp/86/這裏是目前的代碼 – 2014-09-11 11:36:29

+0

確定了這麼遠 - http://jsfiddle.net/LsMZp/89/ – 2014-09-11 11:50:07

+0

我認爲它完成了。它是否可以跨瀏覽器工作? http://jsfiddle.net/LsMZp/90/ – 2014-09-11 12:09:08