前端 - css3動畫怎樣對幀的理解?
問題描述
第一種:
@keyframes slow {0% { background-position: -0px -291px;}25% { background-position: -602px -0px;}50% { background-position: -302px -291px;}75% { background-position: -151px -291px;}100% { background-position: -0px -291px;} } /*動畫切換的方式是一幀一幀的改變*/-webkit-animation-timing-function: steps(1, start);
第二種:
$spriteWidth: 140px; // 精靈寬度 @keyframes run { 0% { background-position: 0 0; } 100% { background-position: -($spriteWidth * 12) 0; // 12幀 }}#sprite { width: $spriteWidth; height: 144px; background: url('../images/sprite.png') 0 0 no-repeat; animation: run 0.6s steps(12) infinite;}
1,什么叫“一幀一幀的改變”, steps(1, start);該如何理解?2,第二種直接“-($spriteWidth * 12) 0”我就看不懂了,為什么這樣寫?
問題解答
回答1:1. 什么叫“一幀一幀的改變”, steps(1, start);該如何理解?animation-timing-function 中 steps 的用法參見這篇
steps 詳解
2. 第二種直接“-($spriteWidth * 12) 0”我就看不懂了,為什么這樣寫?首先顯然這是 Scss 文件(一種 css 預(yù)編譯文件)
定義了一個變量:$spriteWidth
-($spriteWidth * 12) 這句就是一個運(yùn)算呀 => -(140px*12)
回答2:1: steps(1, start)我在MDN上剛好看到一個解釋
This keyword represents the timing function steps(1, start). Using this timing function, the animation jumps immediately to the end state and stay in that position until the end of the animation.
就是說你的動畫幀一開始就馬上跳到結(jié)束了,所以你看見的是keyframes里面5個幀一幀一幀地切換。如果沒有steps(1, start),就會是一個平滑移動的效果。
2: -($spriteWidth * 12)應(yīng)該是指把你這個動畫分成12幀,每一幀你的背景右移-($spriteWidth * 12)這個長度
相關(guān)文章:
1. PHP單例模式2. mysql - 關(guān)于數(shù)據(jù)緩存策略方面的疑惑3. mysql無法刪除字段(錯誤1091),但是對該字段設(shè)置主鍵后就可刪除,為什么?4. mysql - eclispe無法打開數(shù)據(jù)庫連接5. 數(shù)據(jù)庫 - mysql中有沒查看數(shù)據(jù)大小的函數(shù)??6. 老師 我是一個沒有學(xué)過php語言的準(zhǔn)畢業(yè)生 我希望您能幫我一下7. mysql如何配置遠(yuǎn)程php外網(wǎng)鏈接數(shù)據(jù)庫8. mysql如何判斷數(shù)據(jù)不存在則插入呢?9. 導(dǎo)入數(shù)據(jù)庫不成功10. Mysql 關(guān)于 FOUND_ROWS() 和 ROW_COUNT() 函數(shù)
