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

scroll to top functionality #5620

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
34 changes: 34 additions & 0 deletions assets/js/scrollToTop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
document.addEventListener('DOMContentLoaded', function () {
let scrollToTopBtn = document.getElementById('scrollToTopBtn');
let footer = document.querySelector('.td-footer');

if (!scrollToTopBtn || !footer) return;

function adjustButtonPosition() {
let footerTop = footer.getBoundingClientRect().top;
let windowHeight = window.innerHeight;

if (footerTop < windowHeight + 40) {
scrollToTopBtn.style.bottom = windowHeight - footerTop + 40 + 'px';
} else {
scrollToTopBtn.style.bottom = '40px';
}
}

window.onscroll = function () {
if (
document.body.scrollTop > 200 ||
document.documentElement.scrollTop > 200
) {
scrollToTopBtn.style.display = 'block';
} else {
scrollToTopBtn.style.display = 'none';
}

adjustButtonPosition();
};

scrollToTopBtn.onclick = function () {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
});
37 changes: 34 additions & 3 deletions assets/scss/_styles_project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

> li {
display: inline;

> a {
@extend .btn;
margin: 0.25rem;
Expand All @@ -47,7 +48,9 @@
.l-get-started-buttons {
@extend .l-buttons;

> ul > li > a /*, > p > a*/ {
>ul>li>a

/*, > p > a*/ {
@extend .btn-lg;
@extend .btn-secondary;
}
Expand All @@ -67,7 +70,9 @@
@extend .l-buttons;
justify-content: left;

> ul > li > a /*, > p > a*/ {
>ul>li>a

/*, > p > a*/ {
@extend .btn-lg;
@extend .btn-primary;
padding: 20px;
Expand All @@ -80,7 +85,9 @@
@extend .l-buttons;
justify-content: left;

> ul > li > a /*, > p > a*/ {
>ul>li>a

/*, > p > a*/ {
@extend .btn-lg;
@extend .btn-secondary;
padding: 20px;
Expand All @@ -95,9 +102,11 @@
@include media-breakpoint-up(md) {
padding: 0;
}

svg {
height: 48px;
}

.navbar-brand__name {
display: none;
}
Expand Down Expand Up @@ -127,6 +136,7 @@

a {
color: white;

&.external-link:after {
display: none;
}
Expand Down Expand Up @@ -192,6 +202,7 @@

summary {
display: block;

&::-webkit-details-marker {
display: none;
}
Expand Down Expand Up @@ -226,9 +237,11 @@
.td-byline {
margin: 0 !important;
}

.article-meta {
margin: 0;
}

p:first-of-type {
@extend .small;
opacity: 0.65;
Expand Down Expand Up @@ -327,3 +340,21 @@ details {
overflow-y: auto;
}
}

// Scroll-to-top button styling
.scroll-container {
text-align: center;
margin-top: 20px;
}

.scroll-btn {
background-color: #007bff;
color: white;
bottom: 40px;
right: 40px;
display: none;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
z-index: 1000;
border-radius: 50%;
position: fixed;
}
2 changes: 1 addition & 1 deletion content-modules/opentelemetry-java-examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This submodule (content-modules/opentelemetry-java-examples) should not be modified. You'll need:

  • Pull down the latest main branch
  • Rebase your PR branch from the latest from main, and resolve any conflicts (as there are currently conflicts).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, on it mentor. Thanks

4 changes: 3 additions & 1 deletion layouts/partials/hooks/body-end.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{ if hugo.IsProduction -}}
{{ partial "script.html" (dict "src" "js/tracing.js") -}}
{{ partial "script.html" (dict "src" "js/tracing.js") -}}
bintus-ux marked this conversation as resolved.
Show resolved Hide resolved
{{ end -}}
{{ partial "script.html" (dict "src" "js/navScroll.js") -}}
{{ partial "scroll-to-top.html" }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{ partial "scroll-to-top.html" }}
{{ partial "scroll-to-top.html" -}}

{{ partial "script.html" (dict "src" "js/scrollToTop.js") -}}
5 changes: 5 additions & 0 deletions layouts/partials/scroll-to-top.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="scroll-container">
<button id="scrollToTopBtn" class="scroll-btn btn" aria-label="Scroll to top" title="Scroll to top">
<i class="fas fa-arrow-up"></i>
</button>
</div>