久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

前端 - css3動畫怎樣對幀的理解?

瀏覽:142日期:2023-07-14 13:39:14

問題描述

第一種:

@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 預編譯文件)

定義了一個變量:$spriteWidth

-($spriteWidth * 12) 這句就是一個運算呀 => -(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.

就是說你的動畫幀一開始就馬上跳到結束了,所以你看見的是keyframes里面5個幀一幀一幀地切換。如果沒有steps(1, start),就會是一個平滑移動的效果。

2: -($spriteWidth * 12)應該是指把你這個動畫分成12幀,每一幀你的背景右移-($spriteWidth * 12)這個長度

標簽: CSS
相關文章:
主站蜘蛛池模板: 福鼎市| 科尔| 白山市| 锦屏县| 潞西市| 乐都县| 申扎县| 资兴市| 苏尼特右旗| 鸡东县| 阿鲁科尔沁旗| 故城县| 英山县| 平度市| 静乐县| 榆林市| 漳浦县| 县级市| 商都县| 普宁市| 哈巴河县| 休宁县| 沛县| 淮安市| 泰州市| 泰顺县| 北票市| 霞浦县| 青冈县| 姜堰市| 西城区| 北京市| 来宾市| 新乡市| 杨浦区| 海原县| 平果县| 西乌珠穆沁旗| 丰镇市| 远安县| 额尔古纳市|