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

Navbar on scroll #39

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
353 changes: 171 additions & 182 deletions index.html

Large diffs are not rendered by default.

48 changes: 37 additions & 11 deletions src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ footer {

.primary-btn:active {
border: 1px solid #f0e9f2;
color: #f0e9f2;
}
.primary-btn:active img {
filter: invert(0);
}

.primary-btn:active::before {
Expand Down Expand Up @@ -317,7 +321,7 @@ footer {
height: 100vh;
background-color: #363d48;
padding-top: 150px;
z-index: 98;
z-index: 1000;
transition: 0.3s ease-in-out;
}
.mobile-nav.is-active {
Expand Down Expand Up @@ -374,13 +378,36 @@ footer {
opacity: 0;
}

.header-bar-container {
.header-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 0;
position: relative;
z-index: 100;
padding: 1rem 1rem;
position: fixed;
width: 100%;
left: 0;
right: 0;
top: 0;
max-width: 1400px;
margin: 0 auto;
transition: all 0.3s ease-in-out;
}

.header-bar-container {
visibility: hidden;
position: fixed;
width: 100%;
left: 0;
transition: all 0.3s ease-in-out;
z-index: 9999;
}
.header-bar-container.scroll-up {
background-color: #363d48;
opacity: 0.9;
padding: 1.5rem;
}
.header-bar-container.scroll-down {
opacity: 0;
}

.logo-container {
Expand Down Expand Up @@ -569,7 +596,7 @@ footer {
max-width: 90ch;
position: relative;
top: 50%;
transform: translate(0, -70%);
transform: translate(0, -50%);
}

.name-container {
Expand Down Expand Up @@ -603,7 +630,7 @@ footer {
align-items: center;
gap: 2rem;
position: relative;
z-index: 5;
z-index: 1;
}

.btn-down-container {
Expand Down Expand Up @@ -648,7 +675,7 @@ footer {
align-items: center;
text-align: center;
gap: 2rem;
transform: translate(0, -90%);
transform: translate(0, -70%);
}
.intro-container:last-child {
padding-top: 1rem;
Expand All @@ -659,7 +686,7 @@ footer {
}
.btn-down-container {
text-align: center;
transform: translate(-50%, -75%);
transform: translate(-50%, -80%);
gap: 0.5rem;
}
}
Expand Down Expand Up @@ -726,8 +753,7 @@ footer {
display: flex;
align-items: flex-start;
gap: 2rem;
position: relative;
z-index: 5;
z-index: 0;
}

.project-underline {
Expand Down
2 changes: 1 addition & 1 deletion src/css/styles.css.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { hamburgerMenu, mobileSoMeLinks, navLinks } from "../data/constants.mjs";
import { toggleMobileNav, closeMobileNav, closeMobileNavByClickOutside, disableScrollWhenMobileNavOpen } from "./mobileNavHandlers.mjs";
import {
hamburgerMenu,
mobileSoMeLinks,
navLinks,
} from "../../data/constants.mjs";
import {
toggleMobileNav,
closeMobileNav,
closeMobileNavByClickOutside,
disableScrollWhenMobileNavOpen,
} from "./mobileNavHandlers.mjs";

// handle all event listeners on the mobile nav
export function mobileNavEventListeners() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { hamburgerMenu, mobileNav, HTMLbody } from "../data/constants.mjs";
import {
hamburgerMenu,
mobileNav,
HTMLbody,
} from "../../data/constants.mjs";

export function toggleMobileNav() {
// toggles the hamburger menu and mobile nav.
Expand Down
83 changes: 83 additions & 0 deletions src/js/components/skills/renderSkillElements.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { createFigureElement } from "./createFigureElement.mjs";

const skillsContainers = document.querySelectorAll(".skill-slider");

export const renderSkillElements = () => {
// Error handling if container isn't present
if (!skillsContainers.length) {
console.error("No container found with the class [skill-slider]");
}

// create skill elements and save to array
const SkillsElements = [];
SkillsElements.push(
createFigureElement(
"HTML5 icon",
"./src/assets/icons/programming-languages/html-5-svgrepo-com.webp",
"HTML"
)
);
SkillsElements.push(
createFigureElement(
"CSS icon",
"./src/assets/icons/programming-languages/css-3-svgrepo-com.webp",
"CSS"
)
);
SkillsElements.push(
createFigureElement(
"JavaScript icon",
"./src/assets/icons/programming-languages/javascript-svgrepo-com.webp",
"JavaScript"
)
);
SkillsElements.push(
createFigureElement(
"SASS icon",
"./src/assets/icons/programming-languages/sass-svgrepo-com.svg",
"SASS"
)
);
SkillsElements.push(
createFigureElement(
"Figma icon",
"./src/assets/icons/programming-languages/figma-svgrepo-com.webp",
"Figma"
)
);
SkillsElements.push(
createFigureElement(
"Visual Studio Code icon",
"./src/assets/icons/programming-languages/vs-code-svgrepo-com.webp",
"VS Code"
)
);
SkillsElements.push(
createFigureElement(
"GitHub icon",
"./src/assets/icons/programming-languages/github-svgrepo-com.webp",
"GitHub"
)
);
SkillsElements.push(
createFigureElement(
"Git icon",
"./src/assets/icons/programming-languages/git-svgrepo-com.webp",
"Git"
)
);
SkillsElements.push(
createFigureElement(
"WordPress icon",
"./src/assets/icons/programming-languages/wordpress-color-svgrepo-com.webp",
"WordPress"
)
);

// Append each skill element to both/all containers using the cloneNode method
skillsContainers.forEach((skillsContainer) => {
SkillsElements.forEach((element) => {
skillsContainer.appendChild(element.cloneNode(true));
});
});
};
48 changes: 48 additions & 0 deletions src/js/ui/displayHeaderOnScrollUp.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const headerBarContainer = document.querySelector(".header-bar-container");
const headerBar = document.querySelector(".header-bar");

export const displayHeaderOnScrollUp = () => {
// Keep track of last scroll position
let lastScroll = 0;
if (window.scrollY > 100) {
headerBarContainer.classList.add("scroll-down");
}

// updates the initial visibility on the nav bar
headerBarContainer.style.visibility = "visible";

window.addEventListener("scroll", () => {
const currentScroll = window.scrollY;

if (
// If scrolling down add class of scroll-down, it hides the nav bar
lastScroll < currentScroll &&
!headerBarContainer.classList.contains("scroll-down")
) {
headerBarContainer.classList.remove("scroll-up");
headerBarContainer.classList.add("scroll-down");
}

if (
// If scrolling up, add scroll-up class that shows the nav bar, and removes top/bottom padding.
lastScroll > currentScroll &&
headerBarContainer.classList.contains("scroll-down")
) {
headerBarContainer.classList.remove("scroll-down");
headerBarContainer.classList.add("scroll-up");
headerBar.style.padding = "0 1rem";
}

if (
// if scroll position is 100 pixels from the top it removes the class and adds initial padding, results in showing intial nav bar styling
lastScroll < 100 &&
headerBarContainer.classList.contains("scroll-up")
) {
headerBarContainer.classList.remove("scroll-up");
headerBar.style.padding = "1rem 1rem";
}

// Updates the lastScroll to currentScroll to keep track of lates scroll position, needs to be at last
lastScroll = currentScroll;
});
};
31 changes: 0 additions & 31 deletions src/js/utils/renderSkillElements.mjs

This file was deleted.

8 changes: 5 additions & 3 deletions src/js/views/index.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { mobileNavEventListeners } from "../utils/mobileNavEventListeners.mjs";

import { renderSkillElements } from "../utils/renderSkillElements.mjs";
import { mobileNavEventListeners } from "../components/navigation/mobileNavEventListeners.mjs";
import { renderSkillElements } from "../components/skills/renderSkillElements.mjs";
import { displayHeaderOnScrollUp } from "../ui/displayHeaderOnScrollUp.mjs";

// Open/close the mobile nav
mobileNavEventListeners();
// Render Skill elements
renderSkillElements();
// Display nav bar on scroll up
displayHeaderOnScrollUp();
2 changes: 1 addition & 1 deletion src/scss/components/_mobile-nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
height: 100vh;
background-color: variables.$sub-bg-colour;
padding-top: 150px;
z-index: 98;
z-index: 1000;
transition: variables.$transition;
}

Expand Down
5 changes: 5 additions & 0 deletions src/scss/components/_primary-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
// button active effect
.primary-btn:active {
border: 1px solid variables.$main-text-colour;
color: variables.$main-text-colour;

img {
filter: invert(0);
}
}

.primary-btn:active::before {
Expand Down
33 changes: 29 additions & 4 deletions src/scss/layout/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@
// ----------------------------------
// header / nav bar
// ----------------------------------
.header-bar-container {
.header-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 0;
position: relative; // to display header nav bar on top of the mobile nav.
z-index: 100; // to display header nav bar on top of the mobile nav.
padding: 1rem 1rem;
position: fixed;
width: 100%;
left: 0;
right: 0;
top: 0;
max-width: variables.$max-width;
margin: 0 auto;
transition: all variables.$transition;
}

.header-bar-container {
visibility: hidden; // hides the nav bar faster on page refresh
position: fixed;
width: 100%;
left: 0;
transition: all variables.$transition;
z-index: 9999;

// Classes thats get implemented when scrolling
&.scroll-up {
background-color: variables.$sub-bg-colour;
opacity: 0.9;
padding: 1.5rem;
}
&.scroll-down {
opacity: 0;
}
}

.logo-container {
Expand Down
Loading