css3实现苹果loading动画
程序员文章站
2022-03-18 20:10:27
...
如图,苹果的loading图是这样的,今天写小程序的时候,想着加一个图片上传的loading动画,突然想到苹果的这个loading图标,于是想着怎么实现,去百度跟谷歌找了一下,发现没人发过?要不就是我搜索方式不对,于是想起以前做过一个类似的loading动画,由两个半圆组成。于是想着,这个有缺口的圆,想象成一个半圆加另外一个半圆旋转一定角度就可以了,想好就开工。
以下是实现代码:
<!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>
@keyframes roundAni {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.upload-content {
position: relative;
width: 100px;
height: 100px;
background-position: 50% 50%;
background-size: cover;
border: 1px solid red;
margin: 20px 18px 0;
background-color: red;
display: flex;
align-items: center;
justify-content: center;
}
.round-loading-wrap {
position: relative;
width: 50px;
height: 50px;
animation: roundAni 1s linear infinite;
}
.round-loading {
position: absolute;
z-index: 2;
border-radius: 100%;
width: 50px;
height: 50px;
background-color: transparent;
border: 2px solid red;
border-bottom-color: transparent;
border-left-color: transparent;
box-sizing: border-box;
}
.round-loading-1 {
transform: rotate(140deg);
}
</style>
</head>
<body>
<div class="round-loading-wrap">
<div class="round-loading"></div>
<div class="round-loading round-loading-1"></div>
</div>
</body>
</html>
动画的兼容性请自行解决,我用了webpack,会自动加前缀的。
上一篇: css动画之旋转