Today I wanted to play with css animation.
So, my main idea was to create four circles, and then when the user clicks on this circle, then he should go to the center of the page, and then he should become a different shape.
So, I used, transformed and animated.
This is the code that I have written so far.
$(".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>
Now there are some problems that you will notice.
- When you click on any circles, their animation starts from the top corner, and not from where they are.
- When you click on the div again, they return to their position, but are not animated, again I want the animation from another shape to be surrounded and in the same position.
Below is the codepen . Thanks.
css css3 css-transitions css-animations
Nitish
source share