W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
雖然使用@keyframes的 CSS 動(dòng)畫不限于單個(gè)組件,但我們?nèi)韵M鼈儾皇侨值?以避免沖突). 這就是為什么 styled-components 導(dǎo)出 keyframes helper 的原因: 它將生成一個(gè)可以在 APP 應(yīng)用的唯一實(shí)例:
// Create the keyframes const rotate = keyframes` from { transform: rotate(0deg); } to { transform: rotate(360deg); } `; // Here we create a component that will rotate everything we pass in over two seconds const Rotate = styled.div` display: inline-block; animation: ${rotate} 2s linear infinite; padding: 2rem 1rem; font-size: 1.2rem; `;
注意react-native不支持 keyframes. 請(qǐng)參考ReactNative.Animated API.
Keyframes are lazily injected when they're used, which is how they can be code-splitted, so you have to use the css helper for shared style fragments:
const rotate = keyframes`` // ? This will throw an error! const styles = ` animation: ${rotate} 2s linear infinite; `; // ? This will work as intended const styles = css` animation: ${rotate} 2s linear infinite; `
NOTEThis used to work in v3 and below where we didn't code-split keyframes. If you're upgrading from v3, make sure that all your shared style fragments are using the css helper!
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: