# 齿轮loading

# 示例

# 源码

<div class="loader">
  <div class="loader_cogs">
    <div class="loader_cogs__top">
      <div class="top_part"></div>
      <div class="top_part"></div>
      <div class="top_part"></div>
      <div class="top_hole"></div>
    </div>
    <div class="loader_cogs__left">
      <div class="left_part"></div>
      <div class="left_part"></div>
      <div class="left_part"></div>
      <div class="left_hole"></div>
    </div>
    <div class="loader_cogs__bottom">
      <div class="bottom_part"></div>
      <div class="bottom_part"></div>
      <div class="bottom_part"></div>
      <div class="bottom_hole"></div>
    </div>
  </div>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$pink:#f98db9;
$blue:#97ddff;
$yellow:#ffcd66;
$font:'Montserrat', sans-serif;
$heading:rgb(87, 110, 129);
$sub:#F98DB9;

/* Mixins */

@mixin center{
  position:absolute;
  left:0;
  right:0;
  top:0;
  bottom:0;
  margin:auto;
}

@mixin hole{
  border-radius:100%;
  background:white;
  position: absolute;
}

.loader{
  height:100%;
  position:relative;
  margin:auto;
  &_overlay{
    width:150px;
    height:150px;
    background:transparent;
    box-shadow:0px 0px 0px 1000px rgba(255, 255, 255, 0.67), 0px 0px 19px 0px rgba(0, 0, 0, 0.16) inset;
    border-radius:100%;
    z-index:-1;
    @include center;
  }
  &_cogs{
    z-index:-2;
    width:100px;
    height:100px;
    top: -120px !important;
    @include center;
    &__top{
      position:relative;
      width:100px;
      height:100px;
      transform-origin: 50px 50px;
      animation:rotate 10s infinite linear;
      @for $i from 1 through 3{
        div:nth-of-type(#{$i}){
          transform:rotate($i * 30deg)
        }
      }
      div.top_part{
        width:100px;
        border-radius:10px;
        position:absolute;
        height:100px;
        background:$pink;
      }
      div.top_hole{
        width:50px;
        height:50px;
        @include hole;
        @include center;
      }
    }
    &__left{
      position: relative;
      width: 80px;
      transform: rotate(16deg);
      top: 28px;
      transform-origin: 40px 40px;
      animation:rotate_left 10s .1s infinite reverse linear;
      left: -24px;
      height: 80px;
      @for $i from 1 through 3{
        div:nth-of-type(#{$i}){
          transform:rotate($i * 30deg)
        }
      }
      div.left_part{
        width:80px;
        border-radius:6px;
        position:absolute;
        height:80px;
        background:$blue;
      }
      div.left_hole{
        width:40px;
        height:40px;
        @include hole;
        @include center;
      }
    }
    &__bottom{
      position: relative;
      width: 60px;
      top: -65px;
      transform-origin: 30px 30px;
      animation:rotate_left 10.2s .4s infinite linear;
      transform: rotate(4deg);
      left: 79px;
      height: 60px;
      @for $i from 1 through 3{
        div:nth-of-type(#{$i}){
          transform:rotate($i * 30deg)
        }
      }
      div.bottom_part{
        width:60px;
        border-radius:5px;
        position:absolute;
        height:60px;
        background:$yellow;
      }
      div.bottom_hole{
        width:30px;
        height:30px;
        @include hole;
        @include center;
      }
    }
  }
}
/* Animations */

@keyframes rotate{
  from{transform:rotate(0deg)}
  to{transform:rotate(360deg)}
}

@keyframes rotate_left{
  from{transform:rotate(16deg)}
  to{transform:rotate(376deg)}
}

@keyframes rotate_right{
  from{transform:rotate(4deg)}
  to{transform:rotate(364deg)}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

# 源码解析

1、非常的简单粗暴,用3个正方形,每个旋转30°,形成夹角,即可形成齿轮

<div id="example1">
  <div></div>
  <div></div>
  <div></div>
</div>
1
2
3
4
5
#example1{
  position: relative;
  width: 150px;
  height: 150px;
  margin: 0 auto;
  div{
    position: absolute;
    width: 100px;
    height: 100px;
    background: #f98db9;
    top: 50%;
    left: 50%;
    &:first-child{
      transform: translate(-50%, -50%) rotate(0deg)
    }
    &:nth-child(2){
      transform: translate(-50%, -50%) rotate(30deg)
    }
    &:last-child{
      transform: translate(-50%, -50%) rotate(60deg)
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

2、当然,你还可以添加 齿轮 数,样式方面,旋转角度 = 360° / 齿轮个数 / 2 即可

3、然后旋转外层的元素,即可形成整个齿轮旋转动画