課程
/前端開發
/HTML/CSS
/十天精通CSS3
如果暫停了動畫的播放,元素的樣式將回到最原始設置狀態
這個怎么理解呢?有例子嗎?本課例子并沒有在暫停的時候回到起點???
2018-06-09
源自:十天精通CSS3 9-8
正在回答
你的問題可以這樣解決,
@keyframes move {
? 0%{
? ? transform: translateY(90px);
? ? background: orange;
? }
? 15%{
? ? transform: translate(90px,90px);
? 30%{
? ? transform: translate(180px,90px);
? 45%{
? 60%{
? ? transform: translate(90px,0);
? 75%{
? 90%{
? ? transform: translate(90px,180px);
? 100%{
? ? background: green;
}
div {
? width: 200px;
? height: 200px;
? border: 1px solid red;
? margin: 20px auto;
span{
? display: inline-block;
? width: 20px;
? height: 20px;
? background: orange;
? transform: translateY(90px);
? animation-name: move;
? animation-play-state:paused;
div:hover span {
? animation-duration: 10s;
? animation-timing-function: ease-in;
? animation-delay: .2s;
? animation-iteration-count:infinite;
? animation-direction:alternate;
?animation-play-state:running;
animation-fill-mode屬性定義在動畫開始之前和結束之后發生的操作。主要具有四個屬性值:none、forwards、backwords和both。其四個屬性值對應效果如下:
屬性值
效果
none
默認值,表示動畫將按預期進行和結束,在動畫完成其最后一幀時,動畫會反轉到初始幀處
forwards
表示動畫在結束后繼續應用最后的關鍵幀的位置
backwards
會在向元素應用動畫樣式時迅速應用動畫的初始幀
both
元素動畫同時具有forwards和backwards效果
在默認情況之下,動畫不會影響它的關鍵幀之外的屬性,使用animation-fill-mode屬性可以修改動畫的默認行為。簡單的說就是告訴動畫在第一關鍵幀上等待動畫開始,或者在動畫結束時停在最后一個關鍵幀上而不回到動畫的第一幀上?;蛘咄瑫r具有這兩個效果。
例如:讓動畫停在最一幀處。代碼如下:
?animation-fill-mode:forwards;
qq_嶸歸_0
舉報
本課程為CSS3入門教程,深刻詳解CSS3知識讓網頁穿上絢麗裝備
3 回答“另外如果暫停了動畫的播放,元素的樣式將回到最原始設置狀態。”這句話沒太懂意思
3 回答元素的樣式將回到最原始設置狀態。原始設置狀態是指?
5 回答動畫的最終結果是停留在100%的狀態還是最初定義的狀態呢?
2 回答對暫停狀態的疑惑
4 回答我想要鼠標移入時暫停,移出時動畫播放,怎么弄
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-08-21
你的問題可以這樣解決,
如果暫停了動畫的播放,元素的樣式將回到最原始設置狀態
@keyframes move {
? 0%{
? ? transform: translateY(90px);
? ? background: orange;
? }
? 15%{
? ? transform: translate(90px,90px);
? }
? 30%{
? ? transform: translate(180px,90px);
? }
? 45%{
? ? transform: translate(90px,90px);
? }
? 60%{
? ? transform: translate(90px,0);
? }
? 75%{
? ? transform: translate(90px,90px);
? }
? 90%{
? ? transform: translate(90px,180px);
? }
? 100%{
? ? transform: translate(90px,90px);
? ? background: green;
? }
}
div {
? width: 200px;
? height: 200px;
? border: 1px solid red;
? margin: 20px auto;
}
span{
? display: inline-block;
? width: 20px;
? height: 20px;
? background: orange;
? transform: translateY(90px);
? animation-name: move;
? animation-play-state:paused;
}
div:hover span {
? animation-name: move;
? animation-duration: 10s;
? animation-timing-function: ease-in;
? animation-delay: .2s;
? animation-iteration-count:infinite;
? animation-direction:alternate;
?animation-play-state:running;
}
2018-06-14
往后面看會有的,默認的就是none
CSS3中設置動畫時間外屬性
animation-fill-mode屬性定義在動畫開始之前和結束之后發生的操作。主要具有四個屬性值:none、forwards、backwords和both。其四個屬性值對應效果如下:
屬性值
效果
none
默認值,表示動畫將按預期進行和結束,在動畫完成其最后一幀時,動畫會反轉到初始幀處
forwards
表示動畫在結束后繼續應用最后的關鍵幀的位置
backwards
會在向元素應用動畫樣式時迅速應用動畫的初始幀
both
元素動畫同時具有forwards和backwards效果
在默認情況之下,動畫不會影響它的關鍵幀之外的屬性,使用animation-fill-mode屬性可以修改動畫的默認行為。簡單的說就是告訴動畫在第一關鍵幀上等待動畫開始,或者在動畫結束時停在最后一個關鍵幀上而不回到動畫的第一幀上?;蛘咄瑫r具有這兩個效果。
例如:讓動畫停在最一幀處。代碼如下: