Sample code for implementing water drop ripple animation button effect with CSS+JS

Sample code for implementing water drop ripple animation button effect with CSS+JS

The code looks like this:

<!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> 

insert image description here

This concludes this article about the sample code for implementing water drop ripple animation button effect with CSS+JS. For more relevant CSS water drop ripple animation button content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  Detailed explanation of Nginx+Tomcat load balancing cluster installation and configuration case

>>:  Summary of knowledge points on using calculated properties in Vue

Recommend

How to expand the disk space of Linux server

Table of contents Preface step Preface Today I fo...

Vue complete code to implement single sign-on control

Here is a Vue single sign-on demo for your refere...

How to use CSS custom variables in Vue

Table of contents The CSS custom variable functio...

Explain the difference between iframe and frame in HTML with examples

I don't know if you have used the frameset at...

In-depth explanation of Session and Cookie in Tomcat

Preface HTTP is a stateless communication protoco...

A commonplace technique for implementing triangles using CSS (multiple methods)

In some interview experiences, you can often see ...

Teach you how to install mysql database on Mac

Download MySQL for Mac: https://downloads.mysql.c...

VMware virtual machine installation Apple Mac OS super detailed tutorial

Table of contents Summarize Sometimes we need to ...

Vue uses custom instructions to add watermarks to the bottom of the page

Project Scenario Add a custom watermark to the en...

How to install lua-nginx-module module in Nginx

ngx_lua_module is an nginx http module that embed...

Zabbix configures DingTalk's alarm function with pictures

Implementation ideas: First of all, the alarm inf...

MySQL table return causes index invalidation case explanation

Introduction When the MySQL InnoDB engine queries...