-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsb.html
343 lines (297 loc) · 10.1 KB
/
jsb.html
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>备忘录记事本</title>
<style>
body,
html {
height: 100%;
margin: 0;
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
background-color: #f4f4f4;
}
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
#memoContainer {
display: flex;
flex-wrap: wrap;
gap: 20px;
padding: 20px;
overflow-y: auto;
/* 添加垂直滚动条 */
max-height: calc(100vh - 100px);
/* 设置最大高度,减去顶部和底部的空间 */
}
.memo {
flex-basis: calc(33% - 5%);
/* 每个备忘录占据的宽度 */
min-width: 300px;
/* 最小宽度,防止在窄屏设备上太挤 */
max-width: calc(33.33% - 40px);
/* 最大宽度 */
padding: 20px;
border-radius: 15px;
background-color: #fff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
transition: transform 0.3s;
}
@media (max-width: 768px) {
.memo {
width: calc(50% - 40px);
/* 在小屏幕上减少列数 */
}
}
@media (max-width: 480px) {
.memo {
width: 100%;
/* 在更小的屏幕上只有一列 */
}
}
.memo:hover {
transform: scale(1.05);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}
.memo.pinned {
border-left: 4px solid #4CAF50;
background-color: #dff0d8;
}
.memo .actions button {
margin-left: 5px;
padding: 8px 16px;
border: none;
border-radius: 5px;
background-color: #4CAF50;
color: white;
cursor: pointer;
transition: background-color 0.3s;
}
.memo .actions button:hover {
background-color: #45a049;
}
#addMemoBtn {
position: fixed;
bottom: 20px;
right: 20px;
padding: 15px;
border-radius: 50%;
background-color: #4CAF50;
color: white;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
cursor: pointer;
font-size: 24px;
line-height: 24px;
}
#addMemoBtn:hover {
background-color: #45a049;
}
.modal {
display: none;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1000;
overflow-y: auto;
/* 允许滚动长内容 */
transition: opacity 0.3s ease-in-out;
/* 平滑过渡 */
}
.modal-content {
background-color: #fefefe;
margin: 10% auto;
/* 更多顶部空间 */
padding: 30px;
border-radius: 20px;
width: 100%;
max-width: 600px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
text-align: center;
position: relative;
}
.modal-header {
padding-bottom: 20px;
border-bottom: 1px solid #eee;
}
.modal-body {
padding: 20px 0;
}
.modal-footer {
padding-top: 20px;
display: flex;
justify-content: flex-end;
}
.modal-input,
.modal-textarea {
width: 100%;
height: 30px;
/* padding: 15px; */
margin-bottom: 20px;
border-radius: 10px;
border: 1px solid #ddd;
outline: none;
/* 移除默认焦点边框 */
transition: border-color 0.3s ease-in-out;
}
.modal-input:focus,
.modal-textarea:focus {
border-color: #4CAF50;
/* 聚焦时改变边框颜色 */
}
button {
margin-left: 10px;
padding: 12px 20px;
border: none;
border-radius: 10px;
background-color: #4CAF50;
color: white;
cursor: pointer;
transition: background-color 0.3s ease-in-out;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div id="memoContainer"></div>
<button id="addMemoBtn">+</button>
<div id="editModal" class="modal">
<div class="modal-content">
<span class="modal-close" onclick="closeModal()">×</span>
<div class="modal-header">
<h2 id="modalTitle">备忘录</h2>
</div>
<div class="modal-body">
<input type="text" id="modalTitleInput" class="modal-input" placeholder="标题">
<textarea id="modalContentInput" class="modal-input" placeholder="内容"></textarea>
</div>
<div class="modal-footer">
<button onclick="saveMemo()">保存</button>
<button onclick="closeModal()">取消</button>
</div>
</div>
</div>
<script>
var memos = JSON.parse(localStorage.getItem('memos')) || [];
var currentMemoId = null;
function createMemoElement(memo) {
var memoDiv = document.createElement('div');
memoDiv.className = 'memo ' + (memo.pinned ? 'pinned' : '');
memoDiv.innerHTML = `
<div class="title">${memo.title}</div>
<div class="time">${new Date(memo.time).toLocaleString()}</div>
<div class="content">${memo.content}</div>
<div class="actions">
<button onclick="editMemo(${memo.id})">编辑</button>
<button onclick="pinMemo(${memo.id})">置顶</button>
<button onclick="deleteMemo(${memo.id})">删除</button>
</div>
`;
return memoDiv;
}
function renderMemos() {
var container = document.getElementById('memoContainer');
container.innerHTML = '';
memos.forEach((memo, index) => {
container.appendChild(createMemoElement(memo));
});
}
function openModal(memoId) {
currentMemoId = memoId;
document.getElementById('editModal').style.display = 'block';
document.getElementById('modalTitle').innerText = memoId ? '编辑备忘录' : '新增备忘录';
// 如果是编辑模式,设置输入框的值为备忘录的当前值
if (memoId) {
// console.log(1111);
var memo = memos.find(m => m.id === memoId);
document.getElementById('modalTitleInput').value = memo.title;
document.getElementById('modalContentInput').value = memo.content;
} else {
// 如果是新建模式,清空输入框
document.getElementById('modalTitleInput').value = '';
document.getElementById('modalContentInput').value = '';
}
}
function closeModal() {
document.getElementById('editModal').style.display = 'none';
currentMemoId = null;
}
function saveMemo() {
var title = document.getElementById('modalTitleInput').value;
var content = document.getElementById('modalContentInput').value;
if (currentMemoId) {
var memo = memos.find(m => m.id === currentMemoId);
memo.title = title;
memo.content = content;
} else {
var newMemo = {
id: Date.now(),
title: title,
content: content,
pinned: false,
time: new Date().toISOString()
};
memos.push(newMemo);
}
renderMemos();
saveMemos();
closeModal();
}
function addNewMemo() {
openModal(null);
}
function editMemo(id) {
openModal(id);
}
function pinMemo(id) {
var memo = memos.find(m => m.id === id);
if (memo) {
memo.pinned = !memo.pinned;
// Sort memos by pinned status
memos.sort((a, b) => b.pinned - a.pinned);
renderMemos();
saveMemos();
}
}
function deleteMemo(id) {
var index = memos.findIndex(m => m.id === id);
if (index > -1) {
memos.splice(index, 1);
renderMemos();
saveMemos();
}
}
function saveMemos() {
localStorage.setItem('memos', JSON.stringify(memos));
}
function loadMemos() {
memos = JSON.parse(localStorage.getItem('memos')) || [];
renderMemos();
}
// 获取新增按钮
var addMemoButton = document.getElementById('addMemoBtn');
// 监听新增按钮的点击事件
addMemoButton.addEventListener('click', function () {
// 打开模态框
openModal(null);
});
// function openModal(memoId) {
// currentMemoId = memoId;
// document.getElementById('editModal').style.display = 'block';
// document.getElementById('modalTitle').innerText = memoId ? '编辑备忘录' : '新增备忘录';
// document.getElementById('modalTitleInput').value = ''; // 清空标题输入框
// document.getElementById('modalContentInput').value = ''; // 清空内容输入框
// }
window.onload = loadMemos;
</script>
</body>
</html>