一个css3动画

图片描述

我想点击这个按钮时,让这个按钮四周有一片淡淡的波纹向外扩散,这个好做吗?
像这样:
图片描述

谢谢!

阅读 2.7k
3 个回答
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            .wave{
               background: #FC7171;
               color: white;
               width: 200px;
               height: 200px;
               border-radius: 50%;
               border:none;
               outline: none;
               position: relative;              
            }
        .wave p{
            position: absolute;
            z-index: 7;
            text-align: center;
             display: block;
        }
            
        .animat::before,.animat::after{
          content:"";
          position:absolute;
         background: #FA7C7C;
          background-position:center center;
          border-radius:50%;         
        }
        .animat::before{
          z-index:2;
          animation:wave 2s ease-out infinite;
          -webkit-animation:wave 2s ease-out infinite;
        }
        .animat::after{
          z-index:3;
          animation:wave 2s ease-out .2s infinite;
          -webkit-animation:wave 2s ease-out .2s infinite;
        }
        @keyframes wave{
          0%{
            top: 50%;left: 50%;
            transform: translate(-50%, -50%) scale(1.4);
            width:30px;
            height:30px;
            opacity: 1;
          }
          50%{
            top: 50%;left: 50%;
            transform: translate(-50%, -50%) scale(1);
            width:240px;
            height:240px;
          }
          100%{
            top: 50%;left: 50%;
            transform: translate(-50%, -50%) scale(1);
            width:240px;
            height:240px;
            opacity: 0;
          }
        }
 
      
        </style>
    </head>
    <body>
        <button class="wave"><p>点击计数</p></button>
        <script>
            var btn = document.getElementsByTagName("button")[0];
            var timer;
            btn.onclick = function(){                    
                this.classList.add("animat");
                    if(timer){
                        clearInterval(timer);
                    }
                timer = setTimeout(function(){
                    this.classList.remove("animat");
                }.bind(this),2000);
            }
        </script>
    </body>
</html>

Material Design的波纹效果

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题