Easing with CSS?

106 views Asked by At

I'm trying to replicate the zoom/easing effect when hovering one of the "egg" kind of buttons on this page.

I managed to replicate the zoom effect like this:

.egg_button:hover {
    transform: scale(1.2, 1.2);
}

But how to incorporate the bouncing and easing effect present in the model page?

1

There are 1 answers

1
Weafs.py On

Using @keyframes this is how you can do this:

Demo on dabblet

HTML:

<div class="big">
  <div class="small">
    <img src="http://s25.postimg.org/jydmjdxu3/camera.png" />
  </div>
</div>

CSS:

.big {
    position: relative;
    width: 70px;
    height: 70px;
    border-radius: 100px;
    background-color: black;
    margin: 200px;
    -webkit-animation: zoomOut 1s 1;
    animation: zoomOut 1s 1;
}
.small {
    position: absolute;
    width: 60px;
    height: 60px;
    border-radius: 100px;
    background-color: gray;
    margin-top: 5px;
    margin-left: 5px;
    text-align: center;
    line-height: 68px;
    color: white;
}
.big:hover {
    cursor: pointer;
    -webkit-animation: zoomIn 1s 1;
    animation: zoomIn 1s 1;
    -webkit-transform: scale(1.30);
    transform: scale(1.30);
}
.small:hover {
    cursor: pointer;
    -webkit-animation: bounceHover 0.4s 1;
    animation: bounceHover 0.4s 1;
}
body {
    background-color: lightblue;
}
@-webkit-keyframes zoomIn {
    0% {
        transform: scale(1);
    }
    10% {
        transform: scale(1.4);
    }
    20% {
        transform: scale(1.3);
    }
    30% {
        transform: scale(1.35)
    }
    40% {
        transform: scale(1.3);
    }
    50% {
        transform: scale(1.3);
    }
}
@keyframes zoomIn {
    0% {
        transform: scale(1);
    }
    10% {
        transform: scale(1.4);
    }
    20% {
        transform: scale(1.3);
    }
    30% {
        transform: scale(1.35)
    }
    40% {
        transform: scale(1.3);
    }
    50% {
        transform: scale(1.3);
    }
}
@-webkit-keyframes bounceHover {
    0% {
        line-height: 68px;
    }
    20%{
        line-height: 65px;
    }
    40%{
        line-height: 71px;
    }
    60%{
        line-height: 65px;
    }
    80%{
        line-height: 71px;
    }
    100%{
        line-height: 68px;
    }
}
@keyframes bounceHover {
    0% {
        line-height: 68px;
    }
    20%{
        line-height: 65px;
    }
    40%{
        line-height: 71px;
    }
    60%{
        line-height: 65px;
    }
    80%{
        line-height: 71px;
    }
    100%{
        line-height: 68px;
    }
}
@-webkit-keyframes zoomOut {
    0% {
        transform: scale(1);
    }
    10% {
        transform: scale(1.20);
    }
    20% {
        transform: scale(1.05);
    }
    30% {
        transform: scale(1.15)
    }
    40% {
        transform: scale(1.05);
    }
    50% {
        transform: scale(1.1);
    }
}
@keyframes zoomOut {
    0% {
        transform: scale(1);
    }
    10% {
        transform: scale(1.20);
    }
    20% {
        transform: scale(1.05);
    }
    30% {
        transform: scale(1.15)
    }
    40% {
        transform: scale(1.05);
    }
    50% {
        transform: scale(1.1);
    }
}