簡體   English   中英

CSS關鍵幀動畫

[英]CSS Keyframes animation

我需要CSS動畫方面的幫助。 說我有以下動畫

from {left: 0; opacity: 1}
to {left: 20%; opacity: 0.8}

當我將鼠標懸停在上面時可以使用,但是當我進行鼠標離開時,我希望動畫朝相反的方向移動,即首先將不透明度恢復為1,然后再將其保持為0。

您可以使用use:

[selector]:not(:focus) {
    /* animation code */
}

工作

 @keyframes example { from {background-color: red;} to {background-color: yellow;} } @-webkit-keyframes example { from {background-color: red;} to {background-color: yellow;} } @keyframes example1 { from {background-color: yellow;} to {background-color: red;} } @-webkit-keyframes example1 { from {background-color: yellow;} to {background-color: red;} } /* The element to apply the animation to */ input { width: 100px; height: 25px; background-color: red; } input:focus{ -webkit-animation-name: example; /* Chrome, Safari, Opera */ -webkit-animation-duration: 4s; /* Chrome, Safari, Opera */ animation-name: example; animation-duration: 4s; } input:not(:focus){ -webkit-animation-name: example1; /* Chrome, Safari, Opera */ -webkit-animation-duration: 4s; /* Chrome, Safari, Opera */ animation-name: example1; animation-duration: 4s; } 
 <input type="text"/> 

這是您需要的嗎?

from:not(:focus) {
    left: 0; opacity: 1
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM