Skip to content

Commit

Permalink
Show scroll top button
Browse files Browse the repository at this point in the history
  • Loading branch information
neoformit committed Oct 25, 2024
1 parent eafee3d commit 6737d1c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions webapp/home/static/home/css/about.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ section:last-child {
.textbox {
margin: 4rem;
}
#scrollToTop {
position: fixed;
bottom: -5rem;
right: 2rem;
background-color: var(--color);
color: white;
padding: .25rem;
border-radius: 50%;
cursor: pointer;
transition: background-color 0.25s ease;
transition: bottom 1s ease;
font-size: 2rem;
}

/* Lists */
ol.nested > li {
Expand Down
22 changes: 22 additions & 0 deletions webapp/home/templates/home/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,34 @@ <h1> About Galaxy Australia </h1>
{% include 'home/snippets/about/service-levels.html' %}
</section>
</div>

<div
id="scrollToTop"
title="Scroll to top"
data-bs-toggle="tooltip"
onclick="window.scrollTo(0, 0); window.location.hash = '';"
>
<i class="fas fa-arrow-up"></i>
</div>
</main>
{% endblock %}


{% block script %}
<script src="{% static 'home/js/scroll-hash.js' %}" ></script>

<script>
// Scroll event handler to show/hide the floating "scroll-to-top" element
window.addEventListener('scroll', function() {
const scrollPosition = window.scrollY || document.documentElement.scrollTop;
const targetElement = document.getElementById('scrollToTop');
if (scrollPosition > 500) {
targetElement.style.bottom = '2rem'; // Show the element
} else {
targetElement.style.bottom = '-5rem'; // Hide the element
}
});
</script>
{% endblock %}


Expand Down

0 comments on commit 6737d1c

Please sign in to comment.