Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (107 loc) 路 3.58 KB
/
Copy pathscript.js
File metadata and controls
121 lines (107 loc) 路 3.58 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
var i = 0,
a = 0,
isBackspacing = false,
isParagraph = false;
var textArray = [ " My name is IvekIvek 馃構|",
"Simply in love with programming 馃挅|",
"Mostly developig bots, scrapers, web apps 馃惐鈥峾 ",
// "Recently project was Front runner for Uniswap 馃槑|",
"Look latests 4 successful projects down 馃槑|",
"Love reading and good music 馃憣|" ];
var speedForward = 100,
speedWait = 1000,
speedBetweenLines = 1000,
speedBackspace = 25;
typeWriter("output", textArray);
function typeWriter(id, ar) {
var element = $("#" + id),
aString = ar[a],
eHeader = element.children("h1"),
eParagraph = element.children("p");
if (!isBackspacing) {
if (i < aString.length) {
if (aString.charAt(i) == "|") {
isParagraph = true;
// eHeader.removeClass("cursor");
// eParagraph.addClass("cursor");
i++;
setTimeout(function(){ typeWriter(id, ar); }, speedBetweenLines);
} else {
if (!isParagraph) {
eHeader.text(eHeader.text() + aString.charAt(i));
} else {
eParagraph.text(eParagraph.text() + aString.charAt(i));
}
i++;
setTimeout(function(){ typeWriter(id, ar); }, speedForward);
}
} else if (i == aString.length) {
isBackspacing = true;
setTimeout(function(){ typeWriter(id, ar); }, speedWait);
}
} else {
if (eHeader.text().length > 0 || eParagraph.text().length > 0) {
if (eParagraph.text().length > 0) {
eParagraph.text(eParagraph.text().substring(0, eParagraph.text().length - 1));
} else if (eHeader.text().length > 0) {
eParagraph.removeClass("cursor");
eHeader.addClass("cursor");
eHeader.text(eHeader.text().substring(0, eHeader.text().length - 1));
}
setTimeout(function(){ typeWriter(id, ar); }, speedBackspace);
} else {
isBackspacing = false;
i = 0;
isParagraph = false;
a = (a + 1) % ar.length;
setTimeout(function(){ typeWriter(id, ar); }, 50);
}
}
}
/*var TxtRotate = function(el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.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 = 300 - Math.random() * 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('txt-rotate');
for (var i=0; i<elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #666 }";
document.body.appendChild(css);
};*/