Hallo! 👋 Heute erstellen wir Mini-Webanwendung in JavaScript – Notizen-App mit HTML, CSS und JavaScript.
Mit dieser App können Sie Notizen hinzufügen, bearbeiten und löschen, die gespeichert werden in localStorage Dies bedeutet, dass Ihre Notizen bleiben auch nach dem Neuladen der Seite erhalten!
Wir werden uns jeder Schritt der App-Erstellung, damit Sie verstehen, wie es funktioniert, und Ihre eigene Mini-Webanwendung erstellen können reines JS.
Bereit? Los geht's! 🚀
Den vollständigen Quellcode und möglicherweise weitere Verbesserungen finden Sie auf unserer GitHub.

Was unsere App macht
Unsere Notizen-App ermöglicht es Benutzern:
Fügen Sie Notizen mit Überschriften und Beschreibungen hinzu.
Speichern Sie Notizen im Browser, damit die Daten beim erneuten Laden der Seite nicht verloren gehen.
Liste aller erstellten Notizen anzeigen.
Vorhandene Notizen bearbeiten.
Unnötige Notizen löschen.
Jetzt machen wir uns an die Arbeit!
1. Erstellen einer HTML-Struktur
HTML ist für die Struktur unserer Anwendung verantwortlich. Erstellen Sie zunächst eine Datei index.html mit grundlegender Auszeichnung:
<!DOCTYPE html>
<html lang="ru" dir="ltr">
<head>
<meta charset="utf-8">
<title>Приложение для заметок на JavaScript | Coursme</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Подключение иконок -->
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v4.0.0/css/line.css">
</head>
<body>
<!-- Всплывающее окно для добавления/редактирования заметок -->
<div class="popup-box">
<div class="popup">
<div class="content">
<header>
<p>Добавить новую заметку</p>
<i class="uil uil-times"></i> <!-- Кнопка закрытия -->
</header>
<form action="#">
<div class="row title">
<label>Заголовок</label>
<input type="text" spellcheck="false">
</div>
<div class="row description">
<label>Описание</label>
<textarea spellcheck="false"></textarea>
</div>
<button>Сохранить заметку</button>
</form>
</div>
</div>
</div>
<!-- Контейнер для добавления новой заметки -->
<div class="wrapper">
<li class="add-box">
<div class="icon"><i class="uil uil-plus"></i></div>
<p>Добавить новую заметку</p>
</li>
</div>
<script src="script.js"></script>
</body>
</html>
Kurze Erklärung des Codes:
popup-box: Popup-Fenster zum Erstellen einer neuen Notiz. Enthält ein Formular mit Feldern für Titel und Beschreibung.add-box: Ein Element, das ein Popup-Fenster zum Hinzufügen einer neuen Notiz öffnet.
2. Styling mit CSS
Erstellen Sie eine Datei style.css, um unserer Anwendung Stile hinzuzufügen. Hier sind die wichtigsten Stile, die Sie kennen müssen:
/* Import Google Font - Poppins */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background: #FFB3B3;
}
::selection {
color: #fff;
background: #FF6F61;
}
.wrapper {
margin: 40px;
display: grid;
gap: 20px;
grid-template-columns: repeat(auto-fill, 270px);
}
.wrapper li {
height: 260px;
list-style: none;
border-radius: 8px;
padding: 15px 18px 18px;
background: #ffffff;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
transition: transform 0.3s ease-in-out;
}
.wrapper li:hover {
transform: translateY(-5px);
}
.add-box,
.icon,
.bottom-content,
.popup,
header,
.settings .menu li {
display: flex;
align-items: center;
justify-content: space-between;
}
.add-box {
cursor: pointer;
flex-direction: column;
justify-content: center;
}
.add-box .icon {
height: 80px;
width: 80px;
color: #FF6F61;
font-size: 42px;
border-radius: 50%;
justify-content: center;
border: 3px dashed #FF6F61;
}
.add-box p {
color: #FF6F61;
font-weight: 500;
margin-top: 18px;
}
.note {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.note .details {
max-height: 170px;
overflow-y: auto;
}
.note .details::-webkit-scrollbar,
.popup textarea::-webkit-scrollbar {
width: 0;
}
.note .details:hover::-webkit-scrollbar,
.popup textarea:hover::-webkit-scrollbar {
width: 6px;
}
.note .details:hover::-webkit-scrollbar-track,
.popup textarea:hover::-webkit-scrollbar-track {
background: #f3f3f3;
border-radius: 20px;
}
.note .details:hover::-webkit-scrollbar-thumb,
.popup textarea:hover::-webkit-scrollbar-thumb {
background: #ddd;
border-radius: 20px;
}
.note p {
font-size: 20px;
font-weight: 500;
}
.note span {
display: block;
color: #626262;
font-size: 15px;
margin-top: 6px;
}
.note .bottom-content {
padding-top: 8px;
border-top: 1px solid #bbb;
}
.bottom-content span {
color: #7A7A7A;
font-size: 13px;
}
.bottom-content .settings {
position: relative;
}
.bottom-content .settings i {
color: #7A7A7A;
cursor: pointer;
font-size: 16px;
}
.settings .menu {
z-index: 1;
bottom: 0;
right: -5px;
padding: 6px 0;
background: #ffffff;
position: absolute;
border-radius: 6px;
transform: scale(0);
transform-origin: bottom right;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.18);
transition: transform 0.3s ease;
}
.settings.show .menu {
transform: scale(1);
}
.settings .menu li {
height: 28px;
font-size: 15px;
margin-bottom: 2px;
padding: 18px 16px;
cursor: pointer;
box-shadow: none;
border-radius: 0;
justify-content: flex-start;
}
.menu li:last-child {
margin-bottom: 0;
}
.menu li:hover {
background: #f4f4f4;
}
.menu li i {
padding-right: 8px;
}
.popup-box {
position: fixed;
top: 0;
left: 0;
z-index: 2;
height: 100%;
width: 100%;
background: rgba(0, 0, 0, 0.5);
}
.popup-box .popup {
position: absolute;
top: 50%;
left: 50%;
z-index: 3;
width: 100%;
max-width: 420px;
justify-content: center;
transform: translate(-50%, -50%) scale(0.9);
}
.popup-box,
.popup {
opacity: 0;
pointer-events: none;
transition: all 0.35s ease;
}
.popup-box.show,
.popup-box.show .popup {
opacity: 1;
pointer-events: auto;
}
.popup-box.show .popup {
transform: translate(-50%, -50%) scale(1);
}
.popup .content {
border-radius: 8px;
background: #ffffff;
width: calc(100% - 20px);
box-shadow: 0 0 18px rgba(0, 0, 0, 0.12);
}
.content header {
padding: 16px 28px;
border-bottom: 1px solid #bbb;
}
.content header p {
font-size: 21px;
font-weight: 500;
}
.content header i {
color: #9a9898;
cursor: pointer;
font-size: 24px;
}
.content form {
margin: 18px 28px 40px;
}
.content form .row {
margin-bottom: 22px;
}
form .row label {
font-size: 17px;
display: block;
margin-bottom: 7px;
}
form :where(input, textarea) {
height: 52px;
width: 100%;
outline: none;
font-size: 16px;
padding: 0 16px;
border-radius: 5px;
border: 1px solid #aaa;
}
form :where(input, textarea):focus {
box-shadow: 0 3px 5px rgba(0, 0, 0, 0.15);
}
form .row textarea {
height: 155px;
resize: none;
padding: 10px 16px;
}
form button {
width: 100%;
height: 52px;
color: #fff;
outline: none;
border: none;
cursor: pointer;
font-size: 17px;
border-radius: 5px;
background: #FF6F61;
}
@media (max-width: 660px) {
.wrapper {
margin: 12px;
gap: 12px;
grid-template-columns: repeat(auto-fill, 100%);
}
.popup-box .popup {
max-width: calc(100% - 12px);
}
.bottom-content .settings i {
font-size: 18px;
}
}
Kurze Erklärung:
Hintergrund: Wir haben einen schönen rosa Hintergrund für die Seite eingerichtet.
add-box: Element mit "+" Symbol zum Hinzufügen einer neuen Notiz.popup-box: Popup-Fenster, das angezeigt wird, wenn eine Notiz hinzugefügt/bearbeitet wird.
Der Stilcode ist verfügbar in Repositorys.
3. Anwendungslogik in JavaScript
Erstellen Sie eine Datei script.js, um die Funktionalität der Anwendung hinzuzufügen. Wir werden uns die grundlegenden Funktionen ansehen, die für den Betrieb der Anwendung erforderlich sind.
const addBox = document.querySelector(".add-box"),
popupBox = document.querySelector(".popup-box"),
popupTitle = popupBox.querySelector("header p"),
closeIcon = popupBox.querySelector("header i"),
titleTag = popupBox.querySelector("input"),
descTag = popupBox.querySelector("textarea"),
addBtn = popupBox.querySelector("button");
// Monate auf Russisch
const months = ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"];
// Abrufen gespeicherter Notizen aus localStorage, falls vorhanden
const notes = JSON.parse(localStorage.getItem("notes") || "[]");
let isUpdate = false, updateId;
// Öffnen Sie das Fenster, um eine neue Notiz hinzuzufügen
addBox.addEventListener("click", () => {
popupTitle.innerText = "Add a new note";
addBtn.innerText = "Add a note";
popupBox.classList.add("show");
document.querySelector("body").style.overflow = "hidden";
if(window.innerWidth > 660) titleTag.focus();
});
// Schließen Sie das Fenster zum Hinzufügen/Bearbeiten von Notizen
closeIcon.addEventListener("click", () => {
isUpdate = false;
titleTag.value = descTag.value = "";
popupBox.classList.remove("show");
document.querySelector("body").style.overflow = "auto";
});
// Funktion zum Anzeigen aller Notizen
function showNotes() {
if(!notes) return;
document.querySelectorAll(".note").forEach(li => li.remove());
notes.forEach((note, id) => {
let filterDesc = note.description.replaceAll("\n", '<br/>');
let liTag = `<li class="note">
<div class="details">
<p>${note.title}</p>
<span>${filterDesc}</span>
</div>
<div class = "bottom-content">
<span>${note.date}</span>
<div class="settings">
<i onclick="showMenu(this)" class="uil uil-ellipsis-h"></i>
<ul class="menu">
<li onclick="updateNote(${id}, '${note.title}', '${filterDesc}')"><i class="uil uil-pen"></i>Edit</li>
<li onclick="deleteNote(${id})"><i class="uil uil-trash"></i>Delete</li>
</ ul>
</ div>
</ div>
</ li>`;
addBox.insertAdjacentHTML("afterend", liTag);
});
}
showNotes();
// Einstellungsmenü für Notizen anzeigen
function showMenu(elem) {
elem.parentElement.classList.add("show");
document.addEventListener("click", e => {
if(e.target.tagName != "I" || e.target != elem) {
elem.parentElement.classList.remove("show");
}
});
}
// Notiz löschen
function deleteNote(noteId) {
let confirmDel = confirm("Are you sure you want to delete this note?");
if(!confirmDel) return;
notes.splice(noteId, 1);
localStorage.setItem("notes", JSON.stringify(notes));
showNotes();
}
// Notiz aktualisieren
function updateNote(noteId, title, filterDesc) {
let description = filterDesc.replaceAll('<br/>', '\r\n');
updateId = noteId;
isUpdate = true;
addBox.click();
titleTag.value = title;
descTag.value = description;
popupTitle.innerText = "Update note";
addBtn.innerText = "Update note";
}
// Notiz hinzufügen oder aktualisieren
addBtn.addEventListener("click", e => {
e.preventDefault();
let title = titleTag.value.trim(),
description = descTag.value.trim();
if(title || description) {
let currentDate = new Date(),
month = months[currentDate.getMonth()],
day = currentDate.getDate(),
year = currentDate.getFullYear();
let noteInfo = {title, description, date: `${month} ${day}, ${year}`}
if(!isUpdate) {
notes.push(noteInfo);
} else {
isUpdate = false;
notes[updateId] = noteInfo;
}
localStorage.setItem("notes", JSON.stringify(notes));
showNotes();
closeIcon.click();
}
});Detaillierte Erklärung:
addBoxundpopupBox: Diese Variablen verweisen auf Elemente zum Hinzufügen einer neuen Notiz und eines Popups.Funktion zum Öffnen des Formulars: Wenn Sie auf "Hinzufügen" klicken, wird ein Formular zur Dateneingabe geöffnet.
Notizen hinzufügen und speichern: Wenn Sie auf die Schaltfläche "Speichern" klicken, werden die Daten in
localStoragegespeichert.Notizen anzeigen: Alle gespeicherten Notizen werden auf der Seite mit der Funktion
showNotes()angezeigt.
Der Rest des Codes ist verfügbar in Repositorys.
Befund
Jetzt haben Sie eine vollständige Notizen-App in JavaScript! Sie können den Quellcode herunterladen und versuchen, ihn zu verbessern, indem Sie neue Funktionen hinzufügen. Viel Glück bei der Entwicklung! 🚀
