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 Down Progress Bar" To The website #553

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 21 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"write-heading-ids": "docusaurus write-heading-ids"
},
"dependencies": {
"@docusaurus/core": "3.4.0",
"@docusaurus/preset-classic": "3.4.0",
"@docusaurus/core": "^3.4.0",
"@docusaurus/preset-classic": "^3.4.0",
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"lottie-react": "^2.4.0",
Expand Down
47 changes: 41 additions & 6 deletions src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React, { useEffect } from 'react';
import clsx from 'clsx';
import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
Expand All @@ -10,7 +11,7 @@ import Preloader from '../components/Preloader/preloader';
import CursorComponent from '../components/Cursor'

function HomepageHeader() {
const {siteConfig} = useDocusaurusContext();
const { siteConfig } = useDocusaurusContext();
return (
<header className={clsx('hero hero--primary', styles.heroBanner)}>
<div className="container">
Expand All @@ -22,7 +23,7 @@ function HomepageHeader() {
<Link
className="button button--secondary button--lg"
to="/docs/day-01/introduction-to-cpp">
Start Your Challenge Today
Start Your Challenge Today
</Link>
</div>
</div>
Expand All @@ -31,18 +32,52 @@ function HomepageHeader() {
}

export default function Home() {
const {siteConfig} = useDocusaurusContext();
useEffect(() => {
const handleScroll = () => {
const winScroll = document.body.scrollTop || document.documentElement.scrollTop;
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrolled = (winScroll / height) * 100;
document.getElementById('progressBar').style.width = `${scrolled}%`;
};

window.addEventListener('scroll', handleScroll);
handleScroll(); // Initialize on load

return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);

return (
<Layout
title={`Home`}
description="30 days of CPP programming challenge is a step-by-step guide to learn CPP programming language in 30 days. Master the fundamental concepts of CPP Programming easily.
<head />">
<CursorComponent/>

description="30 days of CPP programming challenge is a step-by-step guide to learn CPP programming language in 30 days. Master the fundamental concepts of CPP Programming easily."
>

<HomepageHeader />
<main>
<HomepageFeatures />
</main>
<Preloader />
{/* Inline Styles and Progress Bar Element */}
<div>
<style>
{`
#progressBar {
position: fixed;
top: 0;
left: 0;
width: 0%;
height: 8px;
background-color: #2b9b7f;
z-index: 9999;
transition: width 0.1s ease-out;
}
`}
</style>
<div id="progressBar"></div>
</div>
</Layout>
);
}