-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
108 lines (92 loc) · 3.1 KB
/
script.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
var canvas = document.getElementById('beerCanvas');
var ctx = canvas.getContext('2d');
var particles = [];
var particleCount = 280;
for (var i = 0; i < particleCount; i++) {
particles.push(new particle());
}
function particle() {
this.x = Math.random() * canvas.width;
this.y = canvas.height + Math.random() * 300;
this.speed = 1 + Math.random();
this.radius = Math.random() * 3;
this.opacity = (Math.random() * 100) / 1000;
}
function loop() {
requestAnimationFrame(loop);
draw();
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.globalCompositeOperation = 'lighter';
for (var i = 0; i < particles.length; i++) {
var p = particles[i];
ctx.beginPath();
ctx.fillStyle = 'rgba(255,255,255,' + p.opacity + ')';
ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2, false);
ctx.fill();
p.y -= p.speed;
if (p.y <= -10)
particles[i] = new particle();
}
}
loop();
var TxtType = function(el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 500;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtType.prototype.tick = function() {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">'+this.txt+'</span>';
var that = this;
// var delta = 200 - Math.random() * 100;
var delta = 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function() {
that.tick();
}, delta);
};
window.onload = function() {
var elements = document.getElementsByClassName('typewrite');
for (var i=0; i<elements.length; i++) {
var toRotate = elements[i].getAttribute('data-type');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtType(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".typewrite > .wrap { border-right: 0.08em solid #fff}";
document.body.appendChild(css);
$('[data-github]').each(function () {
var _this = this;
var repo = $(_this).data('github')
fetch('https://api.github.com/repos/' + repo).then(function (response) {
return response.json();
}).then(function (response) {
$(_this).find('[data-forks]').text(response.forks);
$(_this).find('[data-stars]').text(response.stargazers_count);
});
});
};