Skip to content

Commit

Permalink
add function to navigate
Browse files Browse the repository at this point in the history
This function will replace the <main> content with the selected
page and make active it's respective navigation <li> on header.
  • Loading branch information
HectorVilas committed Apr 27, 2023
1 parent 010a37b commit 23ab97f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/functions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import home from "./pages/home.js";
import shop from "./pages/shop.js";

export function addToCart() {
const thisCard = this.closest('.shop-card');
const thisCardMainBtn = thisCard.querySelector('.shop-card-buy');
Expand Down Expand Up @@ -41,3 +44,21 @@ export function toggleFavorite() {
favIcon.classList.add('has-content');
};
}

export function goToPage(page) {
const main = document.querySelector('main');
const previousNavActive = document.querySelector('#navigation .active');
const headerNav = document.querySelector(`.nav-${page}`);
let sections;

previousNavActive?.classList?.remove('active');
headerNav.classList.add('active');
if (page === 'home') {
sections = home();
} else if (page === 'shop') {
sections = shop();
};

main.replaceChildren(...sections);
window.scrollTo(0, 0);
}

0 comments on commit 23ab97f

Please sign in to comment.