-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
201 lines (176 loc) · 6.12 KB
/
script.js
File metadata and controls
201 lines (176 loc) · 6.12 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
window.onload = loadNotes;
document.getElementById("saveBtn").onclick = saveNote;
document.getElementById("themeToggle").onclick = toggleTheme;
function saveNote() {
const input = document.getElementById("noteInput");
const noteText = input.value.trim();
if (!noteText) {
gsap.from("#noteInput", { x: -10, duration: 0.2, repeat: 3, yoyo: true });
return;
}
let notes = JSON.parse(localStorage.getItem("notes")) || [];
notes.push(noteText);
localStorage.setItem("notes", JSON.stringify(notes));
input.value = "";
loadNotes();
}
function loadNotes() {
const notesContainer = document.getElementById("notesContainer");
notesContainer.innerHTML = "";
const notes = JSON.parse(localStorage.getItem("notes")) || [];
notes.forEach((note, index) => {
const noteDiv = document.createElement("div");
noteDiv.className = "note";
noteDiv.style.perspective = "600px"; // 3D perspective
// 3D hover effect
noteDiv.onmousemove = (e) => {
const rect = noteDiv.getBoundingClientRect();
const x = e.clientX - rect.left - rect.width / 2;
const y = e.clientY - rect.top - rect.height / 2;
noteDiv.style.transform = `rotateY(${x / 20}deg) rotateX(${
-y / 20
}deg) scale(1.04)`;
};
noteDiv.onmouseleave = () => {
noteDiv.style.transform = "rotateY(0deg) rotateX(0deg) scale(1)";
};
const previewText = document.createElement("p");
previewText.textContent =
note.length > 60 ? note.slice(0, 60) + "..." : note;
const viewBtn = document.createElement("button");
viewBtn.textContent = "View";
viewBtn.className = "delete-btn";
viewBtn.style.background = "#5c6bc0";
viewBtn.onclick = () => viewNote(note);
const editBtn = document.createElement("button");
editBtn.textContent = "Edit";
editBtn.className = "delete-btn";
editBtn.style.background = "#ffb300";
editBtn.onclick = () => editNote(index, noteDiv, previewText);
const deleteBtn = document.createElement("button");
deleteBtn.textContent = "Delete";
deleteBtn.className = "delete-btn";
deleteBtn.onclick = () => deleteNote(index, noteDiv);
noteDiv.appendChild(previewText);
noteDiv.appendChild(viewBtn);
noteDiv.appendChild(editBtn);
noteDiv.appendChild(deleteBtn);
notesContainer.appendChild(noteDiv);
// GSAP 3D entrance animation
gsap.from(noteDiv, {
duration: 0.7,
y: -40,
opacity: 0,
scale: 0.8,
rotateY: 45,
ease: "back.out(1.7)",
});
if (document.body.classList.contains("dark-mode")) {
noteDiv.classList.add("dark-mode");
previewText.classList.add("dark-mode");
deleteBtn.classList.add("dark-mode");
editBtn.classList.add("dark-mode");
viewBtn.classList.add("dark-mode");
}
});
}
// 3D button press effect
document.querySelectorAll("button").forEach((btn) => {
btn.onmousedown = () => {
btn.style.transform = "scale(0.95) perspective(300px) translateZ(-10px)";
};
btn.onmouseup = () => {
btn.style.transform = "scale(1) perspective(300px) translateZ(0)";
};
});
function editNote(index, noteDiv, noteTextElement) {
const currentText = noteTextElement.textContent;
const editArea = document.createElement("textarea");
editArea.value = currentText;
editArea.className = "edit-area";
const saveEditBtn = document.createElement("button");
saveEditBtn.textContent = "Save";
saveEditBtn.className = "delete-btn";
saveEditBtn.style.background = "#43a047";
saveEditBtn.onclick = () => {
const newText = editArea.value.trim();
if (newText) {
let notes = JSON.parse(localStorage.getItem("notes")) || [];
notes[index] = newText;
localStorage.setItem("notes", JSON.stringify(notes));
loadNotes();
}
};
noteDiv.innerHTML = "";
noteDiv.appendChild(editArea);
noteDiv.appendChild(saveEditBtn);
}
function deleteNote(index, noteElement) {
gsap.to(noteElement, {
duration: 0.4,
opacity: 0,
scale: 0.8,
ease: "power2.in",
onComplete: () => {
let notes = JSON.parse(localStorage.getItem("notes")) || [];
notes.splice(index, 1);
localStorage.setItem("notes", JSON.stringify(notes));
loadNotes();
},
});
}
function viewNote(noteContent) {
const modal = document.createElement("div");
modal.className = "note-modal";
modal.style.position = "fixed";
modal.style.top = "50%";
modal.style.left = "50%";
modal.style.transform = "translate(-50%, -50%)";
modal.style.background = "white";
modal.style.padding = "25px";
modal.style.borderRadius = "14px";
modal.style.boxShadow = "0 15px 40px rgba(0,0,0,0.18)";
const noteText = document.createElement("p");
noteText.textContent = noteContent;
modal.appendChild(noteText);
const closeBtn = document.createElement("button");
closeBtn.textContent = "Close";
closeBtn.className = "delete-btn";
closeBtn.style.background = "#e53935";
closeBtn.onclick = () => document.body.removeChild(modal);
modal.appendChild(closeBtn);
document.body.appendChild(modal);
}
function toggleTheme() {
const body = document.body;
body.classList.toggle("dark-mode");
// 3D animated background color transition
if (body.classList.contains("dark-mode")) {
gsap.to(body, {
backgroundColor: "#121212",
duration: 0.7,
ease: "power2.out",
});
} else {
gsap.to(body, {
backgroundColor: "#e0f7fa",
duration: 0.7,
ease: "power2.out",
});
}
let notes = JSON.parse(localStorage.getItem("notes")) || [];
notes.forEach((_, index) => {
const noteDiv = document.getElementById(`note-${index}`);
if (noteDiv) {
noteDiv.classList.toggle("dark-mode");
}
});
const themeToggleBtn = document.getElementById("themeToggle");
if (body.classList.contains("dark-mode")) {
themeToggleBtn.textContent = "Light Theme";
themeToggleBtn.style.background = "#ffb300";
} else {
themeToggleBtn.textContent = "Dark Theme";
themeToggleBtn.style.background = "#5c6bc0";
}
}