-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain-es5.js
More file actions
132 lines (98 loc) · 3.28 KB
/
main-es5.js
File metadata and controls
132 lines (98 loc) · 3.28 KB
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
// HELPERS
'use strict';
function getColor(idx) {
var colors = ['#6ed6a0', '#5bb8ff', '#6e85ff', '#ff8073', '#ffbe32'];
return colors[idx % colors.length];
}
function getAvatar(idx) {
var avatars = ['http://i.imgur.com/kc8uGI4.jpg', 'http://i.imgur.com/D96IPrE.jpg', 'http://i.imgur.com/29unXYe.jpg', 'http://i.imgur.com/I0iaUdD.jpg'];
return avatars[idx % avatars.length];
}
function conicGradient(from, to) {
var gradient = new ConicGradient({
stops: from + ', ' + to,
size: 120
});
return gradient.png;
}
function easing(t) {
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}
// HELPERS
var meter = new FPSMeter({ graph: 1, heat: 1 });
var style = document.createElement('style');
style.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(style);
var gradientCache = new Map();
function conicGradientClass(from, to) {
var className = gradientCache.get(from + to);
if (!className) {
var png = conicGradient(from, to);
className = 'gradient-' + gradientCache.size;
style.innerHTML += '.' + className + ' { background-image: url(\'' + png + '\'); }\n';
gradientCache.set(from + to, className);
}
return className;
}
function drawLine(path, callback) {
var length = path.getTotalLength();
var t = 0;
path.style.strokeDasharray = length + ' ' + length;
requestAnimationFrame(function step() {
t += 1 / 100;
var offset = -(easing(t) * length);
if (t >= 1) {
t = 0;
requestAnimationFrame(callback);
}
path.style.strokeDashoffset = offset;
requestAnimationFrame(step);
meter.tick();
});
}
function changeAvatar(i) {
var player = avatar.animate([{ transform: 'rotateY(0) translateZ(1px)' }, { transform: 'rotateY(90deg) translateZ(1px)' }], {
easing: 'ease-in',
duration: 150
});
player.onfinish = function () {
avatar.style.backgroundImage = 'url(' + getAvatar(i) + ')';
avatar.animate([{ transform: 'rotateY(90deg) translateZ(1px)' }, { transform: 'rotateY(0deg) translateZ(1px)' }], {
easing: 'ease-out',
duration: 150
});
};
}
var progressBar = document.querySelector('#progress-path');
function progressBarAnimation() {
var i = 0;
function drawContinuous() {
i++;
changeAvatar(i);
var gradientClass = conicGradientClass(getColor(i + 1), getColor(i));
avatarBox.className = 'avatar-box ' + gradientClass;
}
drawLine(progressBar, drawContinuous);
drawContinuous();
}
// MAIN
var avatarBox = document.querySelector('.avatar-box');
var avatar = document.querySelector('.avatar');
avatar.style.display = 'none';
avatarBox.style.transform = 'scale(0)';
var player = avatarBox.animate([{ transform: 'scale(0)' }, { transform: 'scale(1.25)', offset: 0.9 }, { transform: 'scale(1)', offset: 1 }], {
easing: 'ease-in-out',
duration: 400,
delay: 1000,
fill: 'forwards'
});
player.onfinish = function () {
avatar.style.display = 'block';
player = avatar.animate([{ transform: 'scale(0)' }, { transform: 'scale(1)' }], {
easing: 'ease-in-out',
duration: 200
});
player.onfinish = function () {
progressBarAnimation();
};
};