Skip to content

simple and customizable way to create sticky content elements

Notifications You must be signed in to change notification settings

karthick-cs/react-sticky-content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Sticky Content

This project implements a sticky sidebar web component using React hooks. The sidebar element will stick to the top of the viewport when scrolling down, but will stop sticking when reaching the bottom of the content container.

Features:

  • Utilizes React hooks, including useState and useEffect, for managing the sidebar behavior.
  • Calculates and sets the sidebar width and top position using the getBoundingClientRect() method.
  • Adds or removes the CSS class sticky on the sidebar element based on the scroll position of the page.
  • Handles scroll events to dynamically update the sticky behavior.
  • Can be easily integrated into a larger web application as a reusable component.

Usage

  • Install dependencies by running npm install or yarn install.
  • Import the StickySidebar component from this project into your React application.
  • Include the StickySidebar component in your desired layout, and customize the sidebar and content container elements using CSS classes.
  • Customize the behavior by adjusting the handleScroll function or component props, if needed.
  • Enjoy a sticky sidebar that enhances your web application's user experience! In the project directory, you can run:

npm start

License

This code is released under the MIT License. See LICENSE.md for more information.

Acknowledgements

This project was inspired by various examples of sticky sidebar implementations found in web development communities. Special thanks to the React community for providing an excellent framework for building user interfaces.

About

simple and customizable way to create sticky content elements

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published