私はアニメーションの "ハンバーガー"アイコンが内部にあるはずのメニューを作っています。最初は、私がtransform
を使用し、それがいい感じですが、私は彼らがこのようloookいくつかの手の込んだアニメーション;-)終了時のアニメーションを復帰させよう
追加することを決定しました:
@keyframes animateFirstBar {
0% {
transform: translate(-50%, -200%);
}
50% {
transform: translate(-50%, 0);
}
100% {
transform: translateX(-50%) rotate(-45deg);
}
}
@keyframes animateSecoundBar {
0%, 50% {
transform: translate(-50%, 0);
}
51%, 100% {
transform: translate(-50%, 0) scaleX(.01);
}
}
@keyframes animateThirdBar {
0% {
transform: translate(-50%, 200%);
}
50% {
transform: translate(-50%, 0);
}
100% {
transform: translateX(-50%) rotate(45deg);
}
}
をそして、彼らはこのように使用されています
.main-menu {
$mainMenu: &;
position: fixed;
width: 300px;
height: 100%;
top: 0;
left: 0;
background: #ccc;
transform: translateX(-100%);
transition: $time transform ease-in;
&--active {
transform: none;
#{$mainMenu}__toggle {
transform: none;
background: rgba(0, 0, 0, 0);
}
#{$mainMenu}__toggle-line {
&:nth-of-type(1) {
animation: $time animateFirstBar forwards;
}
&:nth-of-type(2) {
animation: $time animateSecoundBar forwards;
}
&:nth-of-type(3) {
animation: $time animateThirdBar forwards;
}
}
}
&__toggle {
width: $width;
height: $width - 1;
position: absolute;
right: 0;
transform: translateX(100%);
top: 0;
background: yellow;
border: 0;
outline: 0;
transition: $time transform ease-in, $time background linear;
transform-origin: bottom right;
}
&__toggle-line {
width: 60%;
height: $lineHeight;
display: block;
background: black;
position: absolute;
left: 50%;
transition: $time transform ease-in;
top: (50% - ($lineHeight/2));
&:nth-of-type(1) {
animation: none;
transform: translate(-50%, -200%);
}
&:nth-of-type(2) {
animation: none;
transform: translate(-50%, 0);
}
&:nth-of-type(3) {
animation: none;
transform: translate(-50%, 200%);
}
}
}
あなたがここでの例を見ることができます:http://codepen.io/tomekbuszewski/pen/jrzKKR?editors=0100
私の問題は、私は削除に(「出口」にアニメーションを元に戻す方法がわからない、ある--active
修飾子)。私は別のアニメーションを書いたり、JSで時間をかけて削除される別のクラスを追加したりしたくありません。
'backwards'アニメーションの方向を使うことができますが、まだ別のクラスを設定しなければならないと思います。 –
' alternate-reverse'を使ってみましたが、役に立たないです。あなたはいくつかの例を投稿できますか? –
修正済み、nice – Ivaro18