JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="header">
блокнот
</div>
<div class="notepad">
<div class="add-note">
<input type="text" class="topic" value="Заголовок">
<input type="text" class="description" value="Описание">
<div class="button">Добавить (0/10)</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
* {
margin: 0px;
padding: 0px;
color: white;
text-align: center;
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
text-transform: uppercase;
}
.header {
width: 500px;
height: 50px;
background-color: rgb(78, 162, 226);
margin: auto;
margin-top: 25px;
position: relative;
font-size: 42px;
}
.notepad {
width: 500px;
height: 800px;
background-color: #8FC2E9;
margin: auto;
position: relative;
padding-top: 35px;
}
.note {
width: 450px;
height: 50px;
background-color: #3F92D2;
margin: auto;
margin-bottom: 15px;
position: relative;
transition-duration: 0.5s;
}
.note:hover {
width: 475px;
}
.note-description {
width: 475px;
height: 150px;
background-color: #66A3D2;
margin: auto;
position: absolute;
top: 100%;
z-index: 1;
}
.delete-button {
width: 10px;
height: 10px;
background-color: #BF3030;
position: absolute;
top: 10px;
right: 10px;
border-radius: 100%;
z-index: 1;
}
.delete {
opacity: 0;
}
.hide {
display: none;
}
.add-note {
width: 450px;
height: 100px;
margin: auto;
position: absolute;
bottom: 20px;
left: 25px;
}
.topic {
width: 100%;
height: 25px;
border: none;
background-color: #A7CCE9;
outline: none;
color: black;
}
.description {
width: 100%;
height: 50px;
border: none;
background-color: rgb(192, 214, 231);
outline: none;
color: black;
}
.button {
width: 100%;
height: 25px;
background-color: #215C89;
cursor: pointer;
transition-duration: 0.5s;
user-select: none;
}
.button:hover {
background-color: rgba(33, 92, 137, 0.651);
}
JavaScript
var $notepad = document.querySelector('.notepad');
var $button = document.querySelector('.button');
var $topic = document.querySelector('.topic');
var $description = document.querySelector('.description');
var noteQty = 0;
var notes = {};
// Удаление содержимого из инпутов при клике по ним
$topic.addEventListener('click', function () {
$topic.value = '';
})
$description.addEventListener('click', function () {
$description.value = '';
})
var id = localStorage.getItem('id') || 1;
// Добавление элементво из localStorage в объект notes
for (var i = 0; i < localStorage.length; i++) {
if (localStorage.key(i) != 'id') {
notes[localStorage.key(i)] = JSON.parse(localStorage.getItem(localStorage.key(i)));
localStorage.removeItem(localStorage.key(i))
i--;
}
}
// Создание заметок из объекта
for (let noteID in notes) {
// Создание формы заметки
let note = document.createElement('div');
note.classList.add('note');
note.textContent = notes[noteID].topic;
// Создание описания заметки
let noteDescription = document.createElement('div');
noteDescription.classList.add('note-description', 'hide');
noteDescription.textContent = notes[noteID].description;
// Создание кнопки удаления
let deleteButton = document.createElement('div');
deleteButton.classList.add('delete-button', 'hide');
// Добавление обработчика события к кнопке удаления
deleteButton.addEventListener('click', function () {
note.classList.add('delete');
setTimeout(function () {
note.classList.add('hide');
}, 500);
noteQty--;
delete notes[noteID];
localStorage.removeItem(noteID)
$button.textContent = 'Добавить (' + noteQty + '/10)';
})
// Добавление описания заметки и кнопки удаления на форму заметки
note.insertAdjacentElement('afterbegin', noteDescription);
note.insertAdjacentElement('afterbegin', deleteButton);
// Добавление...