效果展示
在这里插入图片描述
Demo代码HTML
<!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">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<section><span></span></section>
</body>
</html>
CSS
html,body{
margin: 0;
height: 100%;
}
body{
display: flex;
justify-content: center;
align-items: center;
background: #263238;
}
section {
width: 650px;
height: 300px;
padding: 10px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
/* 红色边框仅作提示 */
border: 2px solid red;
}
span{
width : 96px;
height: 96px;
border: 10px solid #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
animation: rotation 1s linear infinite;
}
span::after{
position: relative;
content: '';
display: inline-block;
width: 72px;
height: 72px;
border-radius: 50%;
border: 10px solid transparent;
border-bottom-color: #FF3D00;
border-top-color: #FF3D00;
}
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
}
原理解释
动画的核心部分就是span和span::after,section仅作为提示框。
步骤1将span元素设置为
width : 96px;
height: 96px;
border: 10px solid #fff;
效果图如下
步骤2span::after伪元素设置为:
注:红色部分即为span::after,为便于观察才设置为红色
步骤3span::after设置
border: 10px solid transparent;
border-bottom-color: #FF3D00;
border-top-color: #FF3D00;
在这里插入图片描述
步骤4span和span::after
border-radius: 50%;
效果图如下
在这里插入图片描述
步骤5为span添加动画
animation: rotation 1s linear infinite;
/*动画实现*/
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
效果图如下
在这里插入图片描述
Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved