I have a div
which is circle in shape.I have done animation
things with CSS .Now i want to do when circle go to bottom then circle size
remain same (now this is ok for me) but when circle bounce back to top then circle reduce it's size
.I don't know, is it possible with CSS ? I am very week in JS .Can anyone solve my problem or suggest me the right way?
Thanks in advance.
HTML:
<div class="hello"></div>
CSS:
.hello{
width:100px;
height:100px;
border:5px solid black;
border-radius:55px;
}
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
-webkit-animation-name: example;
-webkit-animation-duration: 4s;
animation-name: example;
animation-duration: 4s;
}
@keyframes example {
0% {background-color:red; left:0px; top:0px;}
75% {background-color:green; left:0px; top:200px;}
100% {background-color:red; left:0px; top:0px;}
}
A couple of things. There's a JSFiddle at the bottom which shows everything I list:
height: <whatever>px;
and width:<whatever>px;
to the last stage of your animation. height
and width
values are still the starting values at the 75% stage. animation-fill-mode: forwards;
. I've created an edit on your original JSFiddle with all of the above changes Here .
试试这个- 小提琴
100% {background-color:red; left:0px; top:0px; width:50px;height:50px}
You can modify width
and height
of the div in your keyframes
to get desired effect.
@keyframes example {
0% {background-color:red; left:0px; top:0px;}
75% {background-color:green; left:0px; top:200px;width:100px;height:100px;}
100% {background-color:red; left:0px; top:0px;width:50px;height:50px}
}
We are reducing the width and height of circle in the keyframe 100%
so when the ball bounces back ie from keyframe 75%
to 100%
ball is animated to a smaller size. Note that to keep the size of the ball same till keyframe 75%
we are again defining height:100px
and width:100px
in that keyframe.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.