点击开始检测后出现动态等待转圈效果
![](https://img-blog.csdnimg.cn/e237fc15f0b8435f81f5d9599f7a0350.png)
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
.toast {
display: none;
position: fixed;
flex-direction: column;
justify-content: center;
align-items: center;
width: 18rem;
height: 18rem;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0,0,0,0.2);
border-radius: 1rem;
color: #f0f0f0;
font-size: 2.5rem;
}
.load {
display: inline-block;
margin-bottom: 1.5rem;
height: 4rem;
width: 4rem;
border: 0.4rem solid transparent;
border-top-color: white;
border-left-color: white;
border-bottom-color: white;
animation: circle 1s infinite linear;
-webkit-animation: circle 1s infinite linear; /* Safari 和 Chrome */
border-radius: 50%
}
@-webkit-keyframes circle {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(-360deg)
}
}
</style>
<body>
<div class="toast" id="toast">
<span class="load"></span>
<span>检测中...</span>
</div>
<form action="" method="post">
<input type="button" value="开始检测" id="submit">
</form>
<script src="js/jquery-3.6.0.js"></script>
<script>
var submit = document.getElementById("submit");
var toast = document.getElementById("toast");
submit.onclick = function () {
toast.style.display = "flex";
}
$(function () {
// $('.toast').css({display: 'flex'})
//这里可以写网络请求代码...
$.ajax({
url: '/api/login',
type: 'POST',
data: {username: '111'},
dataType: 'json',
success: function (data) {//请求成功则关闭圈圈
$('.toast').css({display: 'none'})
},
error: function (e) {
console.log(e)
}
})
});
</script>
</body>
</html>
其中需要导入的jQuery包:(如果只需要实现效果不需要写请求代码可以将jQuery代码删除,也不需要下载jQuery包)
动态等待转圈效果