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

Enable Scroll snap on home page #1036

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions assets/scripts/sections/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const updateNavBar = () => {
const topNavbar = document.getElementById('top-navbar')
const navbarToggler = document.getElementById('navbar-toggler')
const themeIcon = document.getElementById('navbar-theme-icon-svg')
const scrollContainer = document.querySelector('body');

if (window.scrollY > 40) {
if (scrollContainer.scrollTop > 40) {
topNavbar?.classList.remove('transparent-navbar')
topNavbar?.classList.add('shadow')

Expand Down Expand Up @@ -44,8 +45,9 @@ document.addEventListener('DOMContentLoaded', function () {
// When the user scrolls down 80px from the top of the document,
// resize the navbar's padding and the logo's font size
const topNavbar = document.getElementById('top-navbar')
const scrollContainer = document.querySelector('body');
if (topNavbar?.classList.contains('homepage')) {
document.addEventListener('scroll', updateNavBar)
scrollContainer.addEventListener('scroll', updateNavBar)
updateNavBar()
}

Expand Down
24 changes: 20 additions & 4 deletions assets/styles/layouts/main.scss
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
/*
/*
Removed smooth scrolling implementation in main.js in favor of
simpler css approach.
See: https://css-tricks.com/snippets/jquery/smooth-scrolling/
See: https://css-tricks.com/snippets/jquery/smooth-scrolling/
*/
*,
html {
html,
:not(.dropdown) {
scroll-behavior: smooth !important;
overflow-y: hidden;
}

body {
position: relative;
overflow-y: scroll;
height: 100vh;
}

body.scroll-container {
scroll-snap-type: y mandatory;
}

/*
Enable scroll snap for home page
*/
div#home,
div.section-holder {
scroll-snap-align: start;
}

/*
Fixes anchor overlapping with header.
See: https://stackoverflow.com/questions/4086107/fixed-page-header-overlaps-in-page-anchors
See: https://stackoverflow.com/questions/4086107/fixed-page-header-overlaps-in-page-anchors
*/
:target::before {
content: '';
Expand Down
6 changes: 3 additions & 3 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
{{ end }}
{{ end }}
<meta name="description" content="{{ $siteDescription }}" />

<!-- import common headers -->
{{- partial "header.html" . -}}
{{- partial "opengraph.html" . -}}

<!--================= add analytics if enabled =========================-->
{{- partial "analytics.html" . -}}
{{ with resources.Get "scripts/core/theme-scheme.js" | fingerprint }}
Expand All @@ -23,7 +23,7 @@
</script>
{{ end }}
</head>
<body data-bs-spy="scroll" data-bs-target="#top-navbar" data-bs-offset="100">
<body data-bs-spy="scroll" data-bs-target="#top-navbar" data-bs-offset="100" {{ if site.Params.features.scrollSnap.enable | default false }}class="scroll-container"{{end}}>

<!--- NAVBAR ------------------------->
{{- partial "navigators/navbar.html" . -}}
Expand Down
Loading