-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkanji.js
59 lines (49 loc) · 1.75 KB
/
kanji.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
var url = "kanji.json";
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// parse all JSON data into a single object
var myObj = JSON.parse(this.responseText);
var cardData = myObj.data;
var totalKanjiLoaded = 0;
var addKanji = 100;
for (var i = 0; i < 100; i++) {
document.getElementById("data").innerHTML +=
"<li class=\"kanji\">" +
"<ul>" +
"<li class=\"card-number\">" + cardData[i]["number"] + "</li>" +
"<li class=\"card-kanji\">" + cardData[i]["kanji"] + "</li>" +
"<li class=\"card-keyword\">" + cardData[i]["keyword"] + "</li>" +
"</ul>" +
"</li>";
}
document.addEventListener("scroll", detectScroll);
function detectScroll() {
document.getElementById("stats").innerHTML =
"Cards loaded: " + document.getElementsByClassName("kanji").length +
"<br /><br />" +
"Window height: " + innerHeight +
"<br />" +
"Document height: " + document.body.scrollHeight +
"<br />" +
"Scrollbar X position: " + scrollX +
"<br />" +
"Scrollbar Y position: " + pageYOffset;
if (document.body.scrollHeight - innerHeight == pageYOffset) {
totalKanjiLoaded += addKanji;
for (var i = totalKanjiLoaded; i < totalKanjiLoaded + addKanji; i++) {
document.getElementById("data").innerHTML +=
"<li class=\"kanji\">" +
"<ul>" +
"<li class=\"card-number\">" + cardData[i]["number"] + "</li>" +
"<li class=\"card-kanji\">" + cardData[i]["kanji"] + "</li>" +
"<li class=\"card-keyword\">" + cardData[i]["keyword"] + "</li>" +
"</ul>" +
"</li>";
}
}
}
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();