今日はCSSアニメーションで遊んでみたいです。CSSアニメーション - 元の位置への位置
私の基本的なアイデアは4つの円を作成してから、ユーザーがその円をクリックするとページの中心に移動してから別の形になるはずです。
私は、変換プロパティとアニメーションプロパティを使用しました。
これは今まで書いたコードです。
$(".circle").click(function(){
if($(this).hasClass('centerOfPage')){
$(this).removeClass('centerOfPage');
}else{
$(this).addClass('centerOfPage');
}
});
.circle{
width: 100px;
height: 100px;
border-radius: 50%;
margin: 10px;
}
.one{
background-color: red;
}
.two{
background-color: blue;
}
.three{
background-color: yellow;
}
.four{
background-color: green;
}
.centerOfPage{
position: fixed;
top: 50%;
left: 50%;
width: 100%;
height: 100%;
border-radius: 5%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
animation : centerOfPageAnimate 3s;
}
@keyframes centerOfPageAnimate {
0% {
top: 0%;
left: 0%;
width: 100px;
height: 100px;
border-radius: 50%;
transform: translate(0, 0);
}
100% {
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 100%;
height: 100%;
border-radius: 5%;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div class="circle one"></div>
<div class="circle two"></div>
<div class="circle three"></div>
<div class="circle four"></div>
</div>
今ここであなたが気づくでしょういくつかの問題が...ある
- 何かの円をクリックすると、その後彼らのアニメーションはありません、彼らはどこから上隅から始まります。
- もう一度divをクリックすると、元の位置に戻りますが、アニメーション化されません。もう一度、アニメーションを他の形から丸めて同じ位置に移動します。
ここにはcodepenがあります。おかげさまで
)たい場合、あなたは位置 'へのすべての前に配置されていなかった要素を、切り替えるとき:fixed' ... – CBroe
@nitz:ここには** [GSAP](http://greensock.com/gsap)**ができますウルのアニメーション:** [Codepen](http://codepen.io/tah_med/pen/pjNReG?editors=001)**。これは簡単なデモですが、ここでは多くのことを改善することができます。しかし、それはあなたにGSAPについての考えを与えるはずです。私はこれがあなたが求めているものではないことを知っていますが、あなたがまだ気づいていないなら、私はあなたにそれを紹介すべきだと思いました。 –