How to create Ripple effect on Click - Material Design

后端 未结 10 1556
南旧
南旧 2020-12-12 11:17

I\'m new to CSS animations and I\'ve been trying to make their animation work for the last hours by looking at their code, but I can\'t make it work for now.

I\'m ta

10条回答
  •  猫巷女王i
    2020-12-12 12:15

    Here is a CSS - only implementation i.e. no javascript required.

    Source: https://ghinda.net/article/css-ripple-material-design/

    body {
      background: #fff;
    }
    
    button {
      position: relative;
      overflow: hidden;
      padding: 16px 32px;
    }
    
    button:after {
      content: '';
      display: block;
      position: absolute;
      left: 50%;
      top: 50%;
      width: 120px;
      height: 120px;
      margin-left: -60px;
      margin-top: -60px;
      background: #3f51b5;
      border-radius: 100%;
      opacity: .6;
    
      transform: scale(0);
    }
    
    @keyframes ripple {
      0% {
        transform: scale(0);
      }
      20% {
        transform: scale(1);
      }
      100% {
        opacity: 0;
        transform: scale(1);
      }
    }
    
    button:not(:active):after {
      animation: ripple 1s ease-out;
    }
    
    /* fixes initial animation run, without user input, on page load.
     */
    button:after {
      visibility: hidden;
    }
    
    button:focus:after {
      visibility: visible;
    }

提交回复
热议问题