Delete Button Animation

Home / Web Code Snippet / Delete Button Animation

Delete Button Animation


https://youtube.com/shorts/A2Hp3iFAC8E?si=_uXIV19zybFrmoMU

HTML CODE:-

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
</head>
<body>
<a href="#" class="btn"><span></span><p>Delete</p></a>
</body>
</html>

CSS CODE:-

  body{
            padding: 0px;
            margin: 0px;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            background-color: black;
        }
        .btn{
            position: relative;
            width: 150px;
            height: 50px;
            background: #424242;
            color: white;
            text-decoration: none;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: 0.5s;
            overflow: hidden;
            border: 2px solid white;
        }
        .active{
            background: green;
        }
        span{
            position: absolute;
            left: 40px;
            width: 18px;
            height: 20px;
            background: white;
            display: inline-block;
            transition: 0.5s;
            border-bottom-right-radius: 3px;
            border-bottom-left-radius:3px;
        }
        .btn:hover span{
            transform: scale(1.5) rotate(60deg) translateY(10px);
        }
        .btn.active span{
            left: 50%;
            transform: translateX(-50%) rotate(-45deg);
            width: 20px;
            height: 10px;
            border-radius:0;
            background-color: transparent;
            border-left: 2px solid white;
            border-bottom: 2px solid white;
        }
        span::before{
            content: "";
            position: absolute;
            top: -3px;
            width: 100%;
            height: 2px;
            background-color: white;
            box-shadow: 12px -2px 0 #424242,
            12px -3px 0 #424242,15px -1px 0 #424242,
            6px -2px 0 white;
            transition: 0.5s;
        }
        .btn.active span::before,
        .btn.active:hover span::before{
            transform: scale(0);
        }
        .btn:hover span::before{
            transform: rotate(-90deg) translateX(50%) translateY(-10px);
        }
        p{
            position: absolute;
            right: 30px;
            color: white;
            font-size: 20px;
            transition: 0.5s;
        }
        .btn:hover p,
        .btn.active p{
            transform:translateX(-50px) translateY(-5px) scale(0);
        }

JS CODE:-

  let btn = document.querySelector('.btn');
    btn.onclick = function(){
        btn.classList.toggle('active');
    }