-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.html
226 lines (193 loc) · 7 KB
/
animation.html
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Animation</title>
<style>
* {
padding: 0;
margin: 0;
}
body {
background: black;
}
.container {
position: relative;
width: 100vw;
height: 100vh;
box-sizing: border-box;
}
.animation-wrapper {
position: absolute;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
width: 100px;
height: 100px;
animation: var(--rotation-period, 5s) linear 0s infinite rotation;
}
.node-wrapper {
position: absolute;
transform: translate(-50%, -50%) rotate(var(--rotation, 5s));
top: 50%;
left: 50%;
width: 100px;
height: 100px;
}
.node {
opacity: 0.5;
position: absolute;
border-radius: 50%;
width: 100px;
height: 100px;
border: 0.1px solid var(--border-color, #fff);
animation: var(--scale-period, 0.8s) ease-in-out 0s infinite alternate periodic-scaling;
}
.node__box {
position: absolute;
border: 1px solid red;
width: 100%;
height: 100%;
}
.controls {
position: absolute;
z-index: 1;
top: 50px;
left: 30px;
background: darkslategray;
border-radius: 10px;
display: flex;
flex-direction: column;
width: 250px;
padding: 10px 20px;
}
.controls label {
color: white;
font-family: sans-serif;
display: flex;
flex-direction: column;
margin-bottom: 10px;
}
.controls label input {
height: 30px;
outline: none;
padding: 0px 10px;
border-radius: 6px;
}
@keyframes periodic-scaling {
from {
transform: scaleY(1);
}
to {
transform: scaleY(var(--scale, 2));
}
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="controls">
<label>Кол-во осей: <input type="number" id="axes" value="10" /></label>
<label>Кол-во окружностей: <input type="number" id="copies" value="10" /></label>
<label>Расстояние от центра: <input type="number" id="diffFromCenter" value="50" /></label>
<label>Период вращения: <input type="number" id="rotation" value="5" step="0.1" /></label>
<label>Коэффициент увеличения: <input type="number" id="scale" value="2" step="0.1" /></label>
<label>Период увеличения: <input type="number" id="scalePeriod" value="0.8" step="0.05" /></label>
<label>Цвет анимации: <input type="color" id="borderColor" value="#ffffff"/></label>
<label>Цвет фона: <input type="color" id="backgroundColor" value="#000000"/></label>
<label>Показать границы: <input type="checkbox" id="showBox" /></label>
</div>
<div class="container"></div>
<script>
// Создание анимации
const createEllipse = ({
rotate = '0',
id,
root,
copies = 1,
diffFromCenter = 100,
showBox
}) => {
const wrapper = document.createElement('div');
wrapper.classList.add('node-wrapper');
wrapper.style.setProperty('--rotation', `${rotate}deg`);
wrapper.setAttribute('data-id', id);
for (let i = 0; i < copies; i++) {
const el = document.createElement('div');
el.classList.add('node');
el.style.top = `${diffFromCenter + i * 8}px`;
if (!i && showBox) {
const box = document.createElement('node__box');
box.classList.add('node__box');
el.appendChild(box);
}
wrapper.appendChild(el);
}
root.appendChild(wrapper);
};
const createAnimation = ({ axes = 10, root = document.body, copies, diffFromCenter, rotation = 5, showBox, scale = 2, scalePeriod = 0.8, borderColor = '#fff'}) => {
const wrapper = document.createElement('div');
wrapper.classList.add('animation-wrapper');
wrapper.style.setProperty('--rotation-period', `${rotation}s`)
wrapper.style.setProperty('--scale', scale);
wrapper.style.setProperty('--scale-period', `${scalePeriod}s`);
wrapper.style.setProperty('--border-color', borderColor);
for (let id = 1; id <= axes; id++) {
createEllipse({
id,
root: wrapper,
rotate: id / axes * 360,
copies,
diffFromCenter,
showBox,
})
}
root.appendChild(wrapper);
}
const root = document.querySelector('.container');
createAnimation({
axes: 10,
copies: 10,
root,
diffFromCenter: 50,
});
// Панель управления
const reset = () => {
root.innerHTML = '';
};
const axes = document.querySelector('#axes');
const copies = document.querySelector('#copies');
const diffFromCenter = document.querySelector('#diffFromCenter');
const showBox = document.querySelector('#showBox');
const rotation = document.querySelector('#rotation');
const scale = document.querySelector('#scale');
const scalePeriod = document.querySelector('#scalePeriod');
const borderColor = document.querySelector('#borderColor');
const backgroundColor = document.querySelector('#backgroundColor');
const listener = () => {
reset();
createAnimation({
root,
axes: +axes.value,
copies: +copies.value,
diffFromCenter: +diffFromCenter.value,
showBox: showBox.checked,
rotation: +rotation.value,
scale: +scale.value,
scalePeriod: +scalePeriod.value,
borderColor: borderColor.value
});
}
[axes, copies, diffFromCenter, showBox, rotation, scale, scalePeriod, borderColor].forEach(control => control.addEventListener('change', listener));
backgroundColor.addEventListener('change', () => {
document.body.style.backgroundColor = backgroundColor.value;
});
</script>
</body>
</html>