css 의 keyframe 을 이용해서 공이 튀는 효과를 구현 해 봤습니다.

셈플로 참고 해 주세요.

 

 

 

 

<!DOCTYPE html>
<html>
<head>
  <style>
    .ball {
      position: absolute;
      top: 200px;
      left: 200px;
      width: 100px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      border-radius: 50%;
      background-color: #FF5722;
    }

    .bounce {
      animation: bounce_frames 0.5s;
      animation-direction: alternate;
      animation-timing-function: cubic-bezier(.5, 0.05, 1, .5);
      animation-iteration-count: 4;
    }

    @keyframes bounce_frames {
      from {transform: translate3d(0, 0, 0);}
      to {transform: translate3d(0, 50px, 0);}
    }

    /* Prefix Support */    /*
    bounce {
      -webkit-animation-name: bounce_frames;
      -webkit-animation-duration: 0.5s;
      -webkit-animation-direction: alternate;
      -webkit-animation-timing-function: cubic-bezier(.5, 0.05, 1, .5);
      -webkit-animation-iteration-count: infinite;
    } 
    @-webkit-keyframes bounce_frames {
      from {
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
      }
      to {
        -webkit-transform: translate3d(0, 200px, 0);
        transform: translate3d(0, 200px, 0);
      }
    }    */
  </style>
</head>

<body>
  <div class="ball bounce" onclick="
      this.classList.remove('bounce');
      setTimeout(()=>{
        this.classList.add('bounce')
      }, 1);
    ">click me!</div>
</body>

</html>

 

+ Recent posts