Skip to content

Commit

Permalink
Update 14-added-local.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Jan 24, 2024
1 parent 5895d04 commit 2cd2e4b
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/js/14-added-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ export function renderFavorite() {
}
}

/**
* Favorites section. Scroll apearence and width control in a desktop breakpoint so that the shadow of a single card fits into the card-list container.
*/
document.addEventListener('DOMContentLoaded', () => {
const listContainer = document.querySelector('.favorites__list');
const listItemSelector = '.fav-filters__item-card';
Expand All @@ -82,23 +79,19 @@ document.addEventListener('DOMContentLoaded', () => {
}
};

// A function for checking the break point and applying styles
const applyStyles = () => {
const screenWidth =
window.innerWidth || document.documentElement.clientWidth;
if (screenWidth >= 1440) {
checkWidth();
} else {
// For smaller screens, reset the established styles
listContainer.style.width = 'auto';
}
};

// We call both functions when the page is loaded
checkScroll();
applyStyles();

// We set up mutation observers to track changes inside the container
const observerScroll = new MutationObserver(mutations => {
checkScroll();
});
Expand All @@ -109,6 +102,5 @@ document.addEventListener('DOMContentLoaded', () => {
});
observerWidth.observe(listContainer, { childList: true, subtree: true });

// We add a window size change listener to update styles when the width is changed
window.addEventListener('resize', applyStyles);
});

0 comments on commit 2cd2e4b

Please sign in to comment.