Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can I make an animation ease in smoothly, but also out smoothly?

I have 4 "A" elements being displayed inline in a div, and I want to make it so that when one is hovered on, its size increases slightly in a smooth manner, and when the mouse is no longer hovering it will smoothly go back to its normal size.

I managed to make the hover smoothly increase the element’s size, but whenever I stop hovering, it snaps back to normal without animation. How would I go about fixing this? Here’s a simple version of what I have.

<!DOCTYPE html>
<style>
    div {
        display: inline-block;
        text-align: center;
    }
    a {
        margin: 0 5px;
        font-size: 20px;
    }
    a:hover {
        text-shadow: 0 0 0px #fff;
        animation: aHover ease 0.3s;
        animation-iteration-count: 1;
        animation-fill-mode: forwards;
    }
    @keyframes aHover {
        0% {
            font-size: 20px;
        }
        100% {
            font-size: 25px;
        }
    }
</style>
<div>
    <a>1</a>
    <a>2</a>
    <a>3</a>
    <a>4</a>
</div>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You might use transition instead of animation.

Also I’d suggest transitioning transform:scale3d instead of font-size. As it works in composition and won’t cause reflow and repaint, thus less laggy.

div {
  display: inline-block;
  text-align: center;
}

a {
  display: inline-block;
  margin: 0 5px;
  font-size: 20px;
  transition: transform .3s;
}

a:hover {
  transform: scale3d(1.25, 1.25, 1);
}
<div>
  <a>1</a>
  <a>2</a>
  <a>3</a>
  <a>4</a>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading