好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

CSS+JS实现水滴涟漪动画按钮效果的示例代码

代码如下所示:

<!DOCTY PE  ht ML >
<html lang="en">
<head>
    < ;m eta charset="UTF-8">
    <meta n am e="viewport" content="width=device-width, in IT ial -s cale=1.0">
    <title>Document</title>
    <style>
        . BT n{ 
            dis play : block; 
            width: 300px; 
            h ei ght: 100px;
            m arg in: 50px; 
            outline: 0; 
            overflow: hidden;  
            position: relative; 
            transition: .3s; 
            cursor: pointer; 
             user-select : none;  
            text-align:  center ; 
            line-height: 100px; 
            font- Size:  50px; 
            background: tomato; 
            color:  # fff;  
            border-radius: 10px;
        }
        .btn>span{ 
            position: absolute; 
            left: 0; 
            top: 0;
            width: 100%; 
            height: 100%;}
        .btn>span :after { 
            content: ''; 
            position: absolute; 
            background: transparent; 
            border-radius:50%; 
            width: 100%; 
            padding -t op: 100%; 
            mar gin -left: -50%; 
            margin-top: -50%; 
            left:  VAR (--x,-100%); 
            top: var(--y,-100%); 
        }
        .btn:active{ 
            background: orange red ;
        }
        .btn>input[type=checkbox]{
            display: none
        }
        .btn>input[type=checkbox]+span:after{
            animation: ripple -i n 1s;
        }
        .btn>input[type=checkbox]:checked+span:after{
            animation: ripple-out 1s;
        }
        @keyframes ripple-in{
             From  {
                transform: scale(0);
                background: rgba(0,0,0,.25)
            }
            to {
                transform: scale(1.5);
                background: transparent
            }
        }
        @keyframes ripple-out{
            f rom  {
                transform: scale(0);
                background: rgba(0,0,0,.25)
            }
            to {
                transform: scale(1.5);
                background: transparent
            }
        }
    </style>
</head>
<body>
    <label class="btn" tabindex="1">
        <input type="checkbox"><span onclick="ripple(this,event)">button</span>
    </label>
</body>

<script>
    function ripple(dom,ev){
        console. LOG (ev)
        var x = ev.offsetX;
        var y = ev.offsetY;
        dom.style.set PR operty('--x',x+'px');
        dom.style.setProperty('--y',y+'px');
}
</script>
</html>

到此这篇关于CSS+JS实现水滴涟漪动画按钮效果的示例代码的 文章 就介绍到这了,更多相关css水滴涟漪动画按钮内容请搜索以前的文章或继续浏览下面的相关文章,希望大家以后多多支持!

总结

以上是 为你收集整理的 CSS+JS实现水滴涟漪动画按钮效果的示例代码 全部内容,希望文章能够帮你解决 CSS+JS实现水滴涟漪动画按钮效果的示例代码 所遇到的问题。

如果觉得 网站内容还不错, 推荐好友。

查看更多关于CSS+JS实现水滴涟漪动画按钮效果的示例代码的详细内容...

  阅读:17次