Skip to content

Commit

Permalink
improve library project
Browse files Browse the repository at this point in the history
in this project I added the **animation** to the modal of adding a book
  • Loading branch information
MahmoodHashem committed Jul 30, 2024
1 parent b9d4aa6 commit 2aa4cee
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion JavaScript-exercises/Library/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2>Add New book</h2>

<div class="btns">
<button class="btn" type="submit" data-add>Add</button>
<button class="btn" data-cancel>Cancel</button>
<button class="btn" type="button" data-cancel>Cancel</button>
</div>

</form>
Expand Down
14 changes: 12 additions & 2 deletions JavaScript-exercises/Library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const bookLists = document.querySelector(".book-lists");
const lastChild = document.querySelector(".add-book");




// This array is for storing the books
let itemArr = [];

Expand All @@ -31,29 +33,37 @@ openModal.addEventListener('click', () => {
title.value = "";
author.value = "";
pages.value = "";
modal.style.animationName = 'showModal'
modal.showModal();

});

addbtn.addEventListener("click", () => {
if (title.value !== "" && author.value !== "" && pages.value !== "") {

const state = getSelectedRadioValue();
const book = new Book(title.value, author.value, pages.value, state === '1' ? true : false);

itemArr.push(createItem(book.title, book.author, book.pages, book.state ? "Read" : "Unread"));


/* This is iterating over each item in the `itemArr` array and inserting each item
into the `bookLists` element before the `lastChild` element. This means that for each item in
the `itemArr`, it is being added to the list of books displayed on the webpage before the
"Add Book" button. */

itemArr.forEach(item => {
bookLists.insertBefore(item, lastChild);
})

}
})

cancel.addEventListener('click', () => {
modal.close();

modal.style.animationName = 'closeModal'
setTimeout(() => {
modal.close()
}, 690);

});

Expand Down
37 changes: 36 additions & 1 deletion JavaScript-exercises/Library/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,43 @@ body {
}

.modal {

border: none;

}


.modal.animate{
transform: translateY(-100%);
opacity: 0;
animation: apear 0.7s ease-in-out forwards;
}

.modal{
animation-duration: 0.7s;

}


@keyframes showModal {
from{
opacity: 0;
transform: translateY(-300px);
}
to{
opacity: 1;
transform: translateY(0);
}
}

@keyframes closeModal {
from{
opacity: 1;
transform: translateY(0);
} to{
opacity: 0;
transform: translateY(-300px);
}

}

.modal::backdrop {
Expand Down

0 comments on commit 2aa4cee

Please sign in to comment.