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

Conversation

Palmistry2310
Copy link
Contributor

@Palmistry2310 Palmistry2310 commented Nov 9, 2024

Pull Request for Resum-Resume 💡

Closes: #538

Describe the add-ons or changes you've made 📃

Requirements fulfilled :
1 A button/icon that appears once the user scrolls down a certain distance.
2 Button should be fixed at the bottom-right corner of the screen.
3 When clicked, the page should smoothly scroll to the top.
4 Ensure the button is hidden when the user is near the top of the page.
5 The button design should match the website’s style and be mobile-friendly.

Tasks:
1 Design the "Scroll to Top" button (icon, size, color).
2 Implement the button in HTML/CSS.
3 Add JavaScript for the smooth scroll functionality.
4 Set the button to appear only when the user scrolls down (e.g., 200px from the top).
5 Test the feature across different devices and browsers.
6 Ensure the feature does not interfere with other elements on the page.

LinkedIn.Resume.Builder.-.Home.-.Google.Chrome.2024-11-09.16-29-31.mp4

Type of change ☑️

What sort of change have you made:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist: ☑️

  • My code follows the guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly wherever it was hard to understand.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added things that prove my fix is effective or that my feature works.
  • Any dependent changes have been merged and published in downstream modules.

Summary by CodeRabbit

  • New Features

    • Introduced a scroll-to-top button that appears when scrolling down the page, enhancing navigation.
  • Style Enhancements

    • Refined styles for the features and testimonials sections, including updated card designs and improved responsiveness.
    • Added hover effects for the footer's social media icons, improving visual interaction.
    • Implemented styles for the scroll-to-top button, including mobile responsiveness and hover effects.

Copy link

coderabbitai bot commented Nov 9, 2024

Walkthrough

The changes in this pull request primarily enhance the index.html file by introducing a scroll-to-top button, along with various style updates across different sections. The new button, which appears when the user scrolls down, is styled for visibility and functionality, enabling smooth scrolling back to the top when clicked. Additionally, the features and testimonials sections have received aesthetic improvements, including refined styles and responsiveness adjustments, while the footer now includes social media icons.

Changes

File Change Summary
index.html Added a scroll-to-top button with associated CSS and JavaScript functionality. Updated styles for features, testimonials, and footer sections for improved aesthetics and responsiveness.

Assessment against linked issues

Objective Addressed Explanation
Add scroll to top feature (Issue #538)

Possibly related issues

Possibly related PRs

Suggested labels

hacktoberfest, level1, hacktoberfest-accepted

Poem

In the land of code, where rabbits hop,
A button appears, with a click, we stop.
Scroll to the top, a swift little feat,
With styles so bright, our journey's complete!
Hopping through sections, so neat and so fine,
A joyful new feature, oh how we shine! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
index.html (3)

907-934: Adjust button positioning to prevent overlap with chatbot

The current right position of 80px might cause the scroll-to-top button to overlap with the chatbot button on smaller screens. Consider adjusting the positioning for better spacing.

 #scroll-to-top {
     position: fixed;
     bottom: 20px;
-    right: 80px;
+    right: 120px; /* Increased spacing to prevent overlap */
 }

 @media (max-width: 768px) {
     #scroll-to-top {
         padding: 12px;
         font-size: 20px;
+        right: 100px; /* Adjust position for mobile */
+        bottom: 30px; /* Increase bottom spacing on mobile */
     }
 }

1077-1079: Enhance button accessibility

The button has good basic accessibility with aria-label, but could be improved further.

-    <button id="scroll-to-top" aria-label="Scroll to Top">
+    <button id="scroll-to-top" 
+            aria-label="Scroll to Top"
+            role="button"
+            aria-hidden="false"
+            style="color: #ffffff; background-color: #007bff;">
       <i class="fas fa-arrow-up"></i>
     </button>

1163-1184: Consider consolidating scroll-related JavaScript code

The scroll-to-top functionality and progress bar implementation are in separate script tags. Consider consolidating them for better maintainability.

 <script>
+    // Scroll-related functionality
+    class ScrollManager {
+        constructor() {
+            this.lastScrollPercentage = 0;
+            this.scrollThreshold = 200;
+            this.progressBar = document.getElementById('progress-bar');
+            this.scrollToTopButton = document.getElementById("scroll-to-top");
+            
+            this.initializeEventListeners();
+        }
+
+        initializeEventListeners() {
+            window.addEventListener('scroll', this.handleScroll.bind(this));
+            this.scrollToTopButton.onclick = this.scrollToTop.bind(this);
+        }
+
+        handleScroll() {
+            this.updateProgressBar();
+            this.toggleScrollButton();
+        }
+
+        updateProgressBar() {
+            const scrollTop = window.scrollY;
+            const windowHeight = document.documentElement.scrollHeight - window.innerHeight;
+            const scrollPercentage = (scrollTop / windowHeight) * 100;
+            
+            this.lastScrollPercentage += (scrollPercentage - this.lastScrollPercentage) * 0.1;
+            this.progressBar.style.width = this.lastScrollPercentage + '%';
+        }
+
+        toggleScrollButton() {
+            if (document.body.scrollTop > this.scrollThreshold || 
+                document.documentElement.scrollTop > this.scrollThreshold) {
+                this.scrollToTopButton.style.display = "block";
+            } else {
+                this.scrollToTopButton.style.display = "none";
+            }
+        }
+
+        scrollToTop() {
+            window.scrollTo({
+                top: 0,
+                behavior: "smooth"
+            });
+        }
+    }
+
+    // Initialize scroll manager
+    new ScrollManager();
 </script>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c606135 and 2b2060b.

📒 Files selected for processing (1)
  • index.html (5 hunks)

@Palmistry2310
Copy link
Contributor Author

@GarimaSingh0109 i have resolved the conflicts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
index.html (2)

Line range hint 1-1803: Remove duplicate sections throughout the file.

The file contains multiple copies of the same sections:

  • 3 copies of the header section
  • 3 copies of the features section
  • 3 copies of the testimonials section
  • 3 copies of the footer section

This duplication makes the code harder to maintain and increases the file size unnecessarily.

Keep only one copy of each section and remove the duplicates. Consider breaking down the file into smaller components:

  1. Create separate files for components:
components/
  ├── header.html
  ├── features.html
  ├── testimonials.html
  └── footer.html
  1. Use server-side includes or a templating system to include these components in the main file.

Line range hint 20-932: Consolidate and organize styles.

The current style organization has several issues:

  1. Multiple <style> tags scattered throughout the file

  2. Duplicate style definitions (e.g., features-card, testimonial-card)

  3. Inconsistent usage of CSS variables

  4. Move all styles to a separate CSS file

  5. Use CSS variables consistently:

+ /* Add to the top of your CSS file */
+ :root {
+   /* Colors */
+   --primary-color: #007bff;
+   --primary-dark: #0056b3;
+   --deep-teal: #003d4d;
+   --dark-slate: #333;
+   --off-white: #f9f9f9;
+   
+   /* Spacing */
+   --section-padding: 60px 20px;
+   --card-gap: 30px;
+   
+   /* Transitions */
+   --transition-speed: 0.3s;
+   
+   /* Breakpoints */
+   --mobile-width: 768px;
+ }
  1. Organize styles by component:
/* Layout */
/* Components */
/* Utilities */
/* Media Queries */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2b2060b and d52478c.

📒 Files selected for processing (1)
  • index.html (5 hunks)

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

Comment on lines +1782 to +1803
<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>
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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add scroll to top feature
2 participants