Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task DOM practice (side menu) — done #410

Merged
merged 7 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
The code was refactored according to the mentor's comments
  • Loading branch information
Mifaresss committed Sep 20, 2022
commit f9ec0f5c51047c364b536d054423339c6df1263b
19 changes: 10 additions & 9 deletions submissions/Mifaresss/js_dom/script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"
'use strict'

function hiddenHomeScreen(event) {
if (event.target.tagName !== 'BUTTON') return false;
Mifaresss marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -12,21 +12,22 @@ function createCards(id, header, img, subHeader, description) {
<h2 class="sub-title">${header}</h2>
<img src="${img}" alt="${header}" class="main__img">
<h3 class="title-description">${subHeader}</h3>
<p class="title-description__text">${description.join('<p class="title-description__text">')}</p>
${description.map(desc => `<p class="title-description__text">${desc}</p>`).join('')}
</li>
`
cardsList.innerHTML = cardsHTML;
}

function showCard(event) {
if (event.target.tagName !== 'BUTTON') return false;
const filterClass = event.target.dataset.f;
const { id, header, img, subHeader, description } = cards.find(card => card.id == filterClass);
function showCard({ target }) {
if (target.classList.contains('menu__btn')) {
const filterClass = target.dataset.f;
const { id, header, img, subHeader, description } = cards.find(card => card.id == filterClass);

createCards(id, header, img, subHeader, description);
createCards(id, header, img, subHeader, description);
}
}

function workBurger() {
function toggleBurgerMenu() {
burger.classList.toggle('_active');
navigation.classList.toggle('_active');
document.body.classList.toggle('_lock');
Expand Down Expand Up @@ -133,7 +134,7 @@ const navigation = document.querySelector('nav');
const burger = document.querySelector('.icon-menu');

burger.addEventListener('click', () => {
workBurger();
toggleBurgerMenu();
});
navigation.addEventListener('click', (event) => {
showCard(event);
Expand Down
Loading