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

added scroll to top feature #1014

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
57 changes: 57 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Toggle Dark Mode
</label> -->
<style>

/* Features Section */
.features {
padding: 60px 20px;
Expand Down Expand Up @@ -182,6 +183,8 @@
</style>




<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down Expand Up @@ -899,6 +902,36 @@
background-color: #3f10ea;
}
</style>

<style>
#scroll-to-top {
position: fixed;
bottom: 20px;
right: 80px;
background-color: #007bff; /* Blue button color */
color: white;
border: none;
border-radius: 50%;
padding: 15px;
font-size: 24px;
display: none; /* Hidden initially */
cursor: pointer;
transition: opacity 0.3s ease;
z-index: 1000; /* Ensure it stays on top */
}

#scroll-to-top:hover {
background-color: #0056b3; /* Darker blue on hover */
}

/* Mobile responsiveness */
@media (max-width: 768px) {
#scroll-to-top {
padding: 12px;
font-size: 20px;
}
}
</style>
</head>

<body>
Expand Down Expand Up @@ -1041,6 +1074,9 @@ <h3>Emily Johnson</h3>
</div>
</section>

<button id="scroll-to-top" aria-label="Scroll to Top">
<i class="fas fa-arrow-up"></i> <!-- Font Awesome Arrow Icon -->
</button>
Comment on lines +1072 to +1074
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix duplicate scroll-to-top implementations and improve accessibility.

There are multiple scroll-to-top buttons in the file:

  1. <button id="scroll-to-top"> at line 1072
  2. <button class="scroll-to-top" id="scrollToTopBtn"> (duplicate implementation)

Additionally, the implementation can be improved for performance and accessibility.

  1. Remove duplicate button implementations and keep only one.
  2. Apply this diff to improve the implementation:
 <button id="scroll-to-top" aria-label="Scroll to Top">
   <i class="fas fa-arrow-up"></i>
 </button>

 <style>
   #scroll-to-top {
     position: fixed;
     bottom: 20px;
     right: 20px;
     background-color: #007bff;
     color: white;
     border: none;
     border-radius: 50%;
     padding: 15px;
     font-size: 24px;
     opacity: 0;
     visibility: hidden;
     cursor: pointer;
     transition: opacity 0.3s ease, visibility 0.3s ease, background-color 0.3s ease;
     z-index: 1000;
   }
   
   #scroll-to-top.visible {
     opacity: 1;
     visibility: visible;
   }
   
   #scroll-to-top:hover {
     background-color: #0056b3;
   }
   
   #scroll-to-top:focus {
     outline: 2px solid #fff;
     outline-offset: 2px;
   }
   
   @media (max-width: 768px) {
     #scroll-to-top {
       padding: 12px;
       font-size: 20px;
     }
   }
 </style>

 <script>
   // Configuration
   const SCROLL_THRESHOLD = 200;
   const THROTTLE_DELAY = 150;
   
   // Throttle function
   function throttle(func, limit) {
     let inThrottle;
     return function(...args) {
       if (!inThrottle) {
         func.apply(this, args);
         inThrottle = true;
         setTimeout(() => inThrottle = false, limit);
       }
     }
   }
   
   const scrollToTopButton = document.getElementById("scroll-to-top");
   
   // Optimized scroll handler with throttling
   const handleScroll = throttle(() => {
     const scrolled = window.scrollY || document.documentElement.scrollTop;
     scrollToTopButton.classList.toggle('visible', scrolled > SCROLL_THRESHOLD);
   }, THROTTLE_DELAY);
   
   // Add event listeners
   window.addEventListener('scroll', handleScroll, { passive: true });
   
   scrollToTopButton.addEventListener('click', () => {
     window.scrollTo({
       top: 0,
       behavior: 'smooth'
     });
   });
   
   // Initial check
   handleScroll();
 </script>

Key improvements:

  • Uses CSS visibility/opacity for smoother transitions
  • Adds keyboard focus styles for accessibility
  • Implements throttling for better scroll performance
  • Uses passive scroll listener
  • Adds initial state check

Also applies to: 905-931, 1783-1801


<!-- Chatbot Button -->
<a href="chatbot.html">
Expand Down Expand Up @@ -1124,7 +1160,28 @@ <h3>Connect With Us</h3>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// Get the button
const scrollToTopButton = document.getElementById("scroll-to-top");

// Show or hide the button based on scroll position
window.onscroll = function () {
if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
scrollToTopButton.style.display = "block"; // Show button
} else {
scrollToTopButton.style.display = "none"; // Hide button
}
};

// Smooth scroll to the top when button is clicked
scrollToTopButton.onclick = function () {
window.scrollTo({
top: 0,
behavior: "smooth"
});
};

</script>
Comment on lines +1782 to +1803
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consolidate and organize scripts.

Current issues with script organization:

  1. Multiple script tags scattered throughout the file

  2. Duplicate script includes (jQuery, Bootstrap, etc.)

  3. Mix of inline and external scripts

  4. Move all scripts to separate files

  5. Organize scripts by functionality:

+ /* Create a directory structure */
+ scripts/
+   ├── vendors/
+   │   ├── jquery.min.js
+   │   ├── bootstrap.min.js
+   │   └── gsap.min.js
+   ├── components/
+   │   ├── scroll-to-top.js
+   │   └── progress-bar.js
+   └── main.js
  1. Load scripts efficiently:
<!-- Add to the bottom of body -->
<!-- Vendor scripts -->
<script src="scripts/vendors/jquery.min.js"></script>
<script src="scripts/vendors/bootstrap.min.js"></script>
<script src="scripts/vendors/gsap.min.js"></script>

<!-- Application scripts -->
<script src="scripts/components/scroll-to-top.js"></script>
<script src="scripts/components/progress-bar.js"></script>
<script src="scripts/main.js"></script>


</body>

Expand Down