前端手写题 - 手写loading效果
1. 考察点
(1)水平垂直居中。
(2)animation动画api的使用。
(3)中间文本loading,逆着旋转,即可实现中间内容不动,外环旋转。
2. 代码
<!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>手写loading</title>
<style>
#root {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#loading {
width: 5vw;
height: 5vw;
border: 2px solid rgba(0, 0, 0, 0.2);
border-top-color: rgba(0, 0, 0);
border-radius: 100%;
display: flex;
justify-content: center;
align-items: center;
animation: circle infinite 0.75s linear;
}
#text {
animation: text infinite 0.75s linear;
}
@keyframes text {
from {
-webkit-transform: rotate(0deg)
}
to {
-webkit-transform: rotate(-360deg);
}
}
@keyframes circle {
from {
-webkit-transform: rotate(0deg)
}
to {
-webkit-transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div id="root">
<div id="loading">
<span id="text">loading</span>
</div>
</div>
</body>
</html>