当前位置: 移动技术网 > IT编程>开发语言>JavaScript > CSS+JS实现水滴涟漪动画按钮效果的示例代码

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

2020年08月27日  | 移动技术网IT编程  | 我要评论
代码如下所示:<!doctype html><html lang="en"><head> <meta charset="u

代码如下所示:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>document</title>
    <style>
        .btn{ 
            display: block; 
            width: 300px; 
            height: 100px;
            margin: 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-top: 100%; 
            margin-left: -50%; 
            margin-top: -50%; 
            left: var(--x,-100%); 
            top: var(--y,-100%); 
        }
        .btn:active{ 
            background: orangered;
        }
        .btn>input[type=checkbox]{
            display: none
        }
        .btn>input[type=checkbox]+span:after{
            animation: ripple-in 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{
            from {
                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.setproperty('--x',x+'px');
        dom.style.setproperty('--y',y+'px');
}
</script>
</html>

在这里插入图片描述

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

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网