From eb4d670b67bbc2bcc83b4883c612cc243665eb9d Mon Sep 17 00:00:00 2001 From: Neeru <161798182+neeru24@users.noreply.github.com> Date: Sun, 10 Nov 2024 09:22:10 +0000 Subject: [PATCH] Back to Top Button Disappears on Start Writing Tab During Scroll Fixes #1834 --- start_writing.css | 24 ++++++++++++++++++++++++ start_writing.js | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/start_writing.css b/start_writing.css index 92bbefa..9943cf5 100644 --- a/start_writing.css +++ b/start_writing.css @@ -198,6 +198,30 @@ textarea#blogContent::placeholder { color: #D3D3D3; /* Light grey color for dark mode */ } +#backToTop { + position: fixed; + bottom: 20px; + right: 30px; + width: 50px; + height: 50px; + background-color: #007bff; + color: white; + border-radius: 50%; + display: flex; + justify-content: center; + align-items: center; + cursor: pointer; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + transition: opacity 0.3s; + opacity: 0; + visibility: hidden; +} + +#backToTop.show { + opacity: 1; + visibility: visible; +} + .footer-content { font-size: 0.9rem; } diff --git a/start_writing.js b/start_writing.js index 9c15973..37d1e6e 100644 --- a/start_writing.js +++ b/start_writing.js @@ -121,6 +121,26 @@ async function getWritingSuggestions() { } } +// Get the Back to Top button element +const backToTopButton = document.getElementById('backToTop'); + +// Add scroll event to show/hide the button +window.addEventListener('scroll', () => { + if (window.scrollY > 300) { + backToTopButton.classList.add('show'); + } else { + backToTopButton.classList.remove('show'); + } +}); + +// Add click event to scroll to the top smoothly +backToTopButton.addEventListener('click', () => { + window.scrollTo({ + top: 0, + behavior: 'smooth' + }); +}); + document.getElementById("getSuggestions").addEventListener("click", getWritingSuggestions);