点击按钮后的Loading处理

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>


    <style>
        body {
            padding: 0;
            margin: 0;
            background-color: #5c4084;
            height: 100vh;

            display: flex;
            justify-content: center;
            align-items: center;
        }

        .wrapper {
             600px;
            height: 400px;

            background-color: white;

            border-radius: 20px;
            display: flex;
            justify-content: center;
            align-items: center;

            box-shadow: 0 0 10px rgb(197, 184, 184);
        }

        .loading-mask {
            display: none;

            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;

            z-index: 999;
            background-color: rgba(0, 0, 0, 0.5);
        }

        .loading-spinner {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        svg path,
        svg rect {
            fill: #409eff;
        }



        .click {
             130px;
            height: 40px;
            background: #32b16bc5;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 400;
            color: #FFFFFF;
            line-height: 40px;
            text-align: center;
            letter-spacing: 1px;
            cursor: pointer;
            text-decoration: none;
            transition: all .3s cubic-bezier(.645, .045, .355, 1);
        }

        .click:hover {
            background: #32B16C;
        }
    </style>

</head>

<body>

    <div class="wrapper">
        <a href="#" class="click"> 点击加载 </a>
    </div>

    <div class="loading-mask">
        <div class="loading-spinner">
            <svg version=" 1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
                y="0px" width="40px" height="40px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;"
                xml:space="preserve">
                <path fill="#000"
                    d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z">
                    <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25"
                        to="360 25 25" dur="0.6s" repeatCount="indefinite" />
                </path>
            </svg>
        </div>
    </div>
</body>


<script>
    document.querySelector('.click').addEventListener('click', function () {

        var dom = document.querySelector('.loading-mask');
        dom.style.display = 'block';

        setTimeout(() => {
            dom.style.display = 'none';
        }, 3000);

    });
</script>

</html>
原文地址:https://www.cnblogs.com/lbx6935/p/15599007.html