-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
80 lines (70 loc) · 2.14 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
window.onload = function()
{
// create page
init(data_en);
// random colors for created divs
setRandomColors();
// refresh to parallax effect
jQuery(window).trigger('resize').trigger('scroll');
}
function init(commands)
{
// for each git command
commands.forEach(function(entry)
{
// creating parallax div
var newDiv = document.createElement("div");
newDiv.className = 'fullheight parallax-window';
newDiv.setAttribute("data-parallax", "scroll");
newDiv.setAttribute("data-speed", "0.5");
newDiv.setAttribute("data-bleed", "5");
// creating block div
var blockDiv = document.createElement("div");
blockDiv.className = 'command-block';
// creating title
var title = document.createElement("h2");
title.innerText = entry["title"];
blockDiv.appendChild(title);
const MAX_VALUE = 7;
for(let i = 1; i <= MAX_VALUE; i++)
{
// creating description and other texts
if (entry["text_" + i] != undefined)
{
var description = document.createElement("p");
description.innerText = entry["text_" + i];
// append to command div
blockDiv.appendChild(description);
}
// creating commands
if (entry["command_" + i] != undefined)
{
var cmdDiv = document.createElement("div");
cmdDiv.className = 'console-background';
var cmd = document.createElement("p");
cmd.className = 'console-text-own';
cmd.innerText = entry["command_" + i];
// append to command div
cmdDiv.appendChild(cmd);
blockDiv.appendChild(cmdDiv);
}
}
// append to body
newDiv.appendChild(blockDiv);
document.getElementById("content").appendChild(newDiv);
});
}
function setRandomColors()
{
var colors = ['tan', '#06406c', 'teal', 'saddlebrown', '#3700b3', '#b00020', '#f9a825', '#607d8b'];
var boxes = document.querySelectorAll(".fullheight");
var last_color;
for (i = 0; i < boxes.length; i++)
{
// avoid sequence of same color
color = colors[Math.floor(Math.random() * colors.length)];
while(color == last_color) color = colors[Math.floor(Math.random() * colors.length)];
boxes[i].style.backgroundColor = color;
last_color = color;
}
}