-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathj.js
124 lines (118 loc) · 3.05 KB
/
j.js
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
var q = function(x) {
return document.querySelectorAll(x);
}
var rnd = function(min, max) {
return parseInt(Math.random() * (max - min) + min);
}
var shuffle = function(arr) {
return arr.sort(function() {
return Math.random() > 0.5 ? -1 : 1;
});
}
var bg = function() {
var cs = [rnd(60,120),rnd(100,160),rnd(140,200)];
cs = shuffle(cs);
// cs.pop();
return "rgb(" + cs.join(',') + ')';
}
var createEl = function(tag, csname, inner) {
var el = document.createElement(tag);
el.classList.add(csname);
el.innerHTML = inner;
return el;
}
var clon = function(node) {
var ret = node.cloneNode(true);
ret.setAttribute('id', Math.random());
return ret;
}
var genIcons = function(icon, count, csname) {
var con = createEl('div', csname, "");
for (var i = 0; i < count; i++) {
con.appendChild(clon(icon));
}
if (count % 1 > 0.1) {
var half = clon(icon);
half.style.width = 4 * (count % 1) + "rem";
con.appendChild(half);
}
return con;
}
var sections = q('section');
for (var i = 0; i < sections.length; i++) {
sections[i].style.background = bg();
}
var charts = q('p.rept');
for (var i = 0; i < charts.length; i++) {
var item = charts[i];
var v = item.getAttribute('data-d');
v = v.split(':');
var a = parseFloat(v[0]);
var b = parseFloat(v[1]);
if (a < b) {
b = (b/a).toFixed(2);
a = 1;
} else {
a = (a/b).toFixed(2);
b = 1;
}
var icon = item.getAttribute('data-icon');
icon = q('#' + icon)[0];
var left = genIcons(icon, a * 3, 'left');
var right = genIcons(icon, b * 3, 'right');
var middle = createEl('div', 'middle', a + ":" + b);
var chel = item.parentNode.querySelector('div.chart');
chel.appendChild(left);
chel.appendChild(middle);
chel.appendChild(right);
}
var clonArea = clon(q('#pet')[0]);
clonArea.setAttribute('width', "196px");
clonArea.setAttribute('height', "196px");
q('#logo')[0].appendChild(clonArea);
var current = 0;
var main = q('main')[0];
var isAnimating = false;
var navs = q('nav a');
var activeNav = function(ac) {
for (var i = 0; i < navs.length; i++) {
navs[i].classList.remove('active');
}
if (ac)
ac.classList.add('active');
}
window.onscroll = function() {
if (isAnimating) {
document.body.scrollTop = window.innerHeight * current;
return;
};
isAnimating = true;
var angle = document.body.scrollTop / window.innerHeight;
if (angle > current) {
current = angle == parseInt(angle) ? angle : parseInt(angle) + 1;
} else if (angle < current) {
current = parseInt(angle);
}
if (current < 0) current = 0;
if (current > 11) current = 11;
main.style.transform = "translateY( -"+100*current+"vh )";
main.parentNode.scrollTop = 0;
document.body.scrollTop = window.innerHeight * current;
activeNav(navs[current-1]);
setTimeout(function() {
isAnimating = false;
}, 750);
};
if (window.location.hash) {
if (q(window.location.hash)) {
setTimeout(function() {
document.body.scrollTop = main.parentNode.scrollTop;
main.parentNode.scrollTop = 0;
}, 100);
}
}
for (var i = 0; i < navs.length; i++) {
navs[i].onclick = function(e) {
document.body.scrollTop = q(this.getAttribute('href'))[0].offsetTop;
};
}