css 按鈕動畫?

如何做一個簡單的動畫
就是當表單送出後
等待送出的時間,按鈕能夠有轉圈讀取的動畫(或之類的)呢?

阅读 3k
1 个回答

给你个dom参考吧

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            display:inline-block;
        }
        .box .snake{
            animation: rotate .8s infinite linear;
            border: 4px solid transparent;
            border-radius: 50%;
            border-top-color: rgb(204, 204, 204); 
            border-left-color: rgb(204, 204, 204); 
            border-bottom-color: rgb(204, 204, 204);
             height: 24px; 
             width: 24px;       
        }
        .btn{
            background-color: #000;
            border: none;
            border-radius: 4px;
            padding: 3px 8px;
            outline: none;
            cursor: pointer;
            line-height: 36px;
            height: 36px;
            color: #ffffff;
            font-size: 16px;
        }
        @keyframes rotate{
            0% {
                transform: rotate(0deg);
            }       
            100% {
                transform: rotate(1turn);
            }
        }
    </style>
</head>
<body>
    <button class="btn">
        按钮
    </button>        
</body>
<script>
    var btn = document.querySelector(".btn");
    btn.onclick = function(){
        this.innerHTML = `<span class="box">
                            <div class="snake" ></div>
                        </span>`;
        this.setAttribute("disabled",true);                
    }
</script>
</html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题