-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
109 lines (90 loc) · 2.73 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
108
109
const container2 = document.getElementsByClassName("container2")[0];
const container3 = document.getElementsByClassName("container3")[0];
const checkIcon = document.getElementById("check-icon");
const xIcon = document.getElementById("x-icon");
let i = 0;
xIcon.addEventListener("click", function () {
typeNote();
});
checkIcon.addEventListener("click", function () {
createNote();
});
container3.addEventListener("keypress", function (e) {
if (e.key === "Enter") {
createNote();
}
});
function typeNote() {
if (container3.style.display == "none") {
container3.style.display = "block";
document.querySelector("textarea").focus();
} else {
container3.style.display = "none";
}
}
function createNote() {
let noteText = document.getElementById("note-text").value;
let node0 = document.createElement("div");
let node1 = document.createElement("h1");
let node2 = document.createElement("sub");
node0.setAttribute("style", "display:flex; align-items:center; margin:auto");
node1.innerHTML = noteText;
node1.setAttribute(
"style",
"width:250px; height:250px; font-size:26px; padding:25px; margin-top:10px; overflow:hidden; box-shadow:0px 10px 24px 0px rgba(0, 0, 0, 0.75)"
);
node1.style.margin = margin();
node1.style.transform = rotate();
node1.style.background = color();
node2.setAttribute(
"style",
"font-size:12px; display:flex; align-items:center; justify-content:center; flex-direction:column; padding-bottom:25px"
);
node2.classList.add("fixed-bottom");
node0.appendChild(node1);
node1.appendChild(node2);
container2.insertAdjacentElement("beforeend", node0);
node0.addEventListener("mouseenter", function () {
node0.style.transform = "scale(1.1)";
});
node0.addEventListener("mouseleave", function () {
node0.style.transform = "scale(1)";
});
node0.addEventListener("click", function () {
node0.style.textDecoration = "line-through";
});
node0.addEventListener("dblclick", function () {
node0.remove();
});
node2.innerHTML = "One click to check, two clicks to delete.";
document.getElementById("note-text").value = "";
}
function margin() {
let random_margin = ["-5px", "1px", "5px", "10px", "15px", "20px"];
return random_margin[Math.floor(Math.random() * random_margin.length)];
}
function rotate() {
let random_rotate = [
"rotate(3deg)",
"rotate(1deg)",
"rotate(-1deg)",
"rotate(-3deg)",
"rotate(-5deg)",
"rotate(-10deg)",
];
return random_rotate[Math.floor(Math.random() * random_rotate.length)];
}
function color() {
let random_color = [
"#c2ff3d",
"#ff3de8",
"#3dc2ff",
"#04e022",
"#bc83e6",
"#ebb328",
];
if (i > random_color.length - 1) {
i = 0;
}
return random_color[i++];
}