How to create a CSS3 rollback effect
I am trying to create a bounce effect at the end of an animation without using any third party code or javascript. I don't know how to do this, just using pure CSS.
Here's what I have so far:
HTML:
<div></div>
<div></div>
<div></div>
CSS
div {
background: tomato;
width: 100px;
height: 100px;
margin-bottom: 10px;
transition: transform 0.3s ease-in;
transform-origin: top left;
}
div:hover {
-webkit-transform: scale3d(5, 5, 5);
transform: scale3d(5);
}
source to share
If you need a very simple bounce, it's as easy as simply changing the jump function from ease-in
to something else, for example cubic-bezier
.
An example of a function cubic-bezier
that bounces would be
cubic-bezier(0.175, 0.885, 0.32, 1.275)
Complete example:
div {
background: tomato;
width: 100px;
height: 100px;
margin-bottom: 10px;
transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
transform-origin: top left;
}
div:hover {
-webkit-transform: scale3d(5, 5, 5);
transform: scale3d(5);
}
<div></div>
<div></div>
<div></div>
You can find some examples of other reliefs at easings.net or the complete cubic bezier editor at cubic-bezier.com .
source to share
I'm a fan of animate.css
http://daneden.github.io/animate.css/
By the way, the first animation is a bounce.
You can extract the code you want from the css file.
Using the animate.css framework, I extracted their bounce animation and created the snippet below:
@-webkit-keyframes bounce {
0%, 20%, 53%, 80%, 100% {
-webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
40%, 43% {
-webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
-webkit-transform: translate3d(0, -30px, 0);
transform: translate3d(0, -30px, 0);
}
70% {
-webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
-webkit-transform: translate3d(0, -15px, 0);
transform: translate3d(0, -15px, 0);
}
90% {
-webkit-transform: translate3d(0,-4px,0);
transform: translate3d(0,-4px,0);
}
}
@keyframes bounce {
0%, 20%, 53%, 80%, 100% {
-webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
40%, 43% {
-webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
-webkit-transform: translate3d(0, -30px, 0);
transform: translate3d(0, -30px, 0);
}
70% {
-webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
-webkit-transform: translate3d(0, -15px, 0);
transform: translate3d(0, -15px, 0);
}
90% {
-webkit-transform: translate3d(0,-4px,0);
transform: translate3d(0,-4px,0);
}
}
.bounce {
-webkit-animation-name: bounce;
animation-name: bounce;
-webkit-transform-origin: center bottom;
transform-origin: center bottom;
}
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
div{background:red; padding:50px;}
<div class="bounce animated">bounce</div>
source to share