我今天想玩css动画。CSS动画 - 对原始位置的位置
所以我的基本想法是创建四个圆圈,然后当用户点击该圆圈时,它应该到页面中心,然后它应该变成其他形状。
所以我用过,转换和动画属性。
这是我写到现在的代码。
$(".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)**可以对哟ur动画:** [Codepen](http://codepen.io/tah_med/pen/pjNReG?editors=001)**。这只是一个快速演示,很多东西都可以在这里改进。但它应该给你一个关于GSAP的想法。我知道这不是你要求的,但如果你不知道,我想我应该向你介绍。 –