How to create CSS3 bounce effect

后端 未结 2 1508
忘了有多久
忘了有多久 2021-02-05 14:07

I am trying to add a bounce effect to the end of the animation without using any 3rd party code or javascript. I managed to create the animation but could not achieve the bounce

2条回答
  •  礼貌的吻别
    2021-02-05 14:39

    If all you need is a very simple bounce, it's as easy as just changing the transition function from ease-in to something else, such as a cubic-bezier.

    An example of a cubic-bezier function that bounces would be

    cubic-bezier(0.175, 0.885, 0.32, 1.275)
    

    A full 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);
    }

    You can find a few examples of other easings at easings.net, or a full cubic-bezier editor at cubic-bezier.com.

提交回复
热议问题