Skip to content

📋 Uses css to add a class to change the nav bar when the user scrolls up. Wes Bos Javascript30 tutorial 24

Notifications You must be signed in to change notification settings

AndrewJBateman/javascript-scroll-navbar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ Javascript Scroll Navbar

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

📄 Table of contents

📚 General info

  • Tutorial Code to add a class to change the nav bar when the user scrolls. Also changes the width of the text div.

📷 Screenshots

Example screenshot.

📶 Technologies

💾 Setup

  • Open index.html in browser. If any code is changed the browser needs to be refreshed.

💻 Code Examples

  • compares scroll position with top of Navigation and adds the 'fixed-nav' class when they are equal.
fixNav = () => {
  console.log('window.scrollY', window.scrollY, 'topOfNav', topOfNav);
  if(window.scrollY >= topOfNav) {
    console.info('window.scrollY >= topOfNav');
    document.body.style.paddingTop = nav.offsetHeight + 'px';
    document.body.classList.add('fixed-nav'); 
  } else {
    document.body.style.paddingTop = 0;
    document.body.classList.remove('fixed-nav'); 
  }
}

🆒 Features

  • At about scrollY = 337px the css class change occurs to 'fixed-nav'.

📋 Status & To-Do List

  • Status: Working.
  • To-Do: Nothing

👏 Inspiration

📁 License

  • N/A

✉️ Contact

About

📋 Uses css to add a class to change the nav bar when the user scrolls up. Wes Bos Javascript30 tutorial 24

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published