diff --git a/app.js b/app.js index c27cee9..0b0d6d1 100644 --- a/app.js +++ b/app.js @@ -2,6 +2,19 @@ window.addEventListener('DOMContentLoaded', () => { let scrollPos = 0; const mainNav = document.getElementById('navbar'); const headerHeight = mainNav.clientHeight; + + // --- New: create back-to-top button --- + const backToTop = document.createElement('button'); + backToTop.id = 'back-to-top'; + backToTop.textContent = '↑ Top'; + backToTop.title = 'Back to top'; + backToTop.style.cssText = 'position:fixed; right:12px; bottom:72px; z-index:9999; padding:8px 10px; border-radius:8px; border:none; background:rgba(0,0,0,0.6); color:#fff; cursor:pointer; display:none;'; + backToTop.addEventListener('click', () => { + window.scrollTo({ top: 0, behavior: 'smooth' }); + }); + document.body.appendChild(backToTop); + // --- end new --- + window.addEventListener('scroll', function() { const currentTop = document.body.getBoundingClientRect().top * -1; if ( currentTop < scrollPos) { @@ -18,6 +31,13 @@ window.addEventListener('DOMContentLoaded', () => { mainNav.classList.add('is-fixed'); } } + // show back-to-top when scrolled down enough + if (currentTop > 300) { + backToTop.style.display = 'block'; + } else { + backToTop.style.display = 'none'; + } + scrollPos = currentTop; }); }) @@ -232,5 +252,5 @@ const attatchMobileMenuToggleFunction = () => { }; document.addEventListener("DOMContentLoaded", function () { - attatchMobileMenuToggleFunction(); + attachMobileMenuToggleFunction(); }); diff --git a/style/style.css b/style/style.css index 23f5bf0..c0441d3 100644 --- a/style/style.css +++ b/style/style.css @@ -46,7 +46,7 @@ section { z-index: 6; } -.navbar-innner-parent { +.navbar-inner-parent { position: relative; width: 100%; height: 5rem; @@ -365,7 +365,7 @@ section { margin-bottom: 0; } /*This is a form style for desktop*/ -.discription-title { +.description-title { display: grid; grid-template-columns: 70% 30%; } @@ -642,7 +642,7 @@ footer .lag { } @media screen and (max-width: 1100px) { /* This is a form style for desktop */ - .discription-title { + .description-title { display: flex; flex-direction: column; justify-content: center;