-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgossip-grid.js
88 lines (83 loc) · 2.78 KB
/
gossip-grid.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
import { gossips } from "./gossip-grid.data.js";
function grid() {
//Ranges
ranges();
// First gossip card, with a form to add new gossips
let form = document.createElement("form");
form.classList.add("gossip");
let textarea = document.createElement("textarea");
let button = document.createElement("button");
button.innerHTML = "Share gossip!";
button.type = "submit";
button.addEventListener("click", (e) => {
e.preventDefault();
let gossip = textarea.value;
if (gossip.length > 0) {
gossips.unshift(gossip);
document.querySelectorAll(".gossip").forEach((card, i) => {
if (i > 0) card.remove();
});
textarea.value = "";
renderGossips();
}
});
form.appendChild(textarea);
form.appendChild(button);
document.body.appendChild(form);
// All other gossip cards
renderGossips();
}
function renderGossips() {
gossips.forEach((gossip) => {
let div = document.createElement("div");
div.classList.add("gossip");
div.innerHTML = gossip;
document.body.appendChild(div);
});
}
function ranges() {
// Ranges
let ranges = document.createElement("div");
ranges.classList.add("ranges");
let widthRange = document.createElement("input");
widthRange.type = "range";
widthRange.id = "width";
widthRange.min = "200";
widthRange.max = "800";
widthRange.value = "400";
widthRange.addEventListener("input", (e) => {
let cards = document.querySelectorAll(".gossip");
cards.forEach((card) => {
card.style.width = e.target.value + "px";
});
});
let fontSizeRange = document.createElement("input");
fontSizeRange.type = "range";
fontSizeRange.id = "fontSize";
fontSizeRange.min = "20";
fontSizeRange.max = "40";
fontSizeRange.value = "30";
fontSizeRange.addEventListener("input", (e) => {
let cards = document.querySelectorAll(".gossip");
cards.forEach((card) => {
card.style.fontSize = e.target.value + "px";
});
});
let backgroundColorRange = document.createElement("input");
backgroundColorRange.type = "range";
backgroundColorRange.id = "background";
backgroundColorRange.min = "20";
backgroundColorRange.max = "75";
backgroundColorRange.value = "50";
backgroundColorRange.addEventListener("input", (e) => {
let cards = document.querySelectorAll(".gossip");
cards.forEach((card) => {
card.style.backgroundColor = `hsl(280, 50%, ${e.target.value}%)`;
});
});
ranges.appendChild(widthRange);
ranges.appendChild(fontSizeRange);
ranges.appendChild(backgroundColorRange);
document.body.appendChild(ranges);
}
export { grid };