I needed to implement infinite bounce effect using pure CSS, so I referred this site and ended up doing this.
.animated {    -webkit-animation-duration: 2.5s;    animation-duration: 2.5s;    -webkit-animation-fill-mode: both;    animation-fill-mode: both;    -webkit-animation-timing-function: linear;    animation-timing-function: linear;    animation-iteration-count: infinite;    -webkit-animation-iteration-count: infinite;  }     @-webkit-keyframes bounce {    0%, 20%, 40%, 60%, 80%, 100% {-webkit-transform: translateY(0);}    50% {-webkit-transform: translateY(-5px);}  }     @keyframes bounce {     0%, 20%, 40%, 60%, 80%, 100% {transform: translateY(0);}    50% {transform: translateY(-5px);}  }     .bounce {     -webkit-animation-name: bounce;    animation-name: bounce;  }    #animated-example {      width: 20px;      height: 20px;      background-color: red;      position: relative;      top: 100px;      left: 100px;      border-radius: 50%;  }    hr {      position: relative;      top: 92px;      left: -300px;      width: 200px;  }  <div id="animated-example" class="animated bounce"></div>  <hr>  Now, my only problem is the bouncing element takes a longer rest before it starts bouncing again. How can I make it bounce smoothly just like the bounce effect we get by using jQuery.animate?
Bounce Animation effect is used to move the element quick up, back, or away from a surface after hitting it.
Go to the app -> res right click on res folder then New -> Android Resource Directory and create an anim Directory. Then right-click on anim folder then go to New -> Animation Resource File and create a bounce.
The long rest in between is due to your keyframe settings. Your current keyframe rules mean that the actual bounce happens only between 40% - 60% of the animation duration (that is, between 1s - 1.5s mark of the animation). Remove those rules and maybe even reduce the animation-duration to suit your needs.
.animated {    -webkit-animation-duration: .5s;    animation-duration: .5s;    -webkit-animation-fill-mode: both;    animation-fill-mode: both;    -webkit-animation-timing-function: linear;    animation-timing-function: linear;    animation-iteration-count: infinite;    -webkit-animation-iteration-count: infinite;  }  @-webkit-keyframes bounce {    0%, 100% {      -webkit-transform: translateY(0);    }    50% {      -webkit-transform: translateY(-5px);    }  }  @keyframes bounce {    0%, 100% {      transform: translateY(0);    }    50% {      transform: translateY(-5px);    }  }  .bounce {    -webkit-animation-name: bounce;    animation-name: bounce;  }  #animated-example {    width: 20px;    height: 20px;    background-color: red;    position: relative;    top: 100px;    left: 100px;    border-radius: 50%;  }  hr {    position: relative;    top: 92px;    left: -300px;    width: 200px;  }  <div id="animated-example" class="animated bounce"></div>  <hr>  Here is how your original keyframe settings would be interpreted by the browser:
translate by 0px in Y axis.translate by 0px in Y axis.translate by 0px in Y axis.translate by 5px in Y axis. This results in a gradual upward movement.translate by 0px in Y axis. This results in a gradual downward movement.translate by 0px in Y axis.translate by 0px in Y axis.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With