smartcomputing123

scripts.js

Jun 22nd, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /*!
  2. * Start Bootstrap - Clean Blog v6.0.8 (https://startbootstrap.com/theme/clean-blog)
  3. * Copyright 2013-2022 Start Bootstrap
  4. * Licensed under MIT (https://github.com/StartBootstrap/startbootstrap-clean-blog/blob/master/LICENSE)
  5. */
  6. window.addEventListener('DOMContentLoaded', () => {
  7. let scrollPos = 0;
  8. const mainNav = document.getElementById('mainNav');
  9. const headerHeight = mainNav.clientHeight;
  10. window.addEventListener('scroll', function() {
  11. const currentTop = document.body.getBoundingClientRect().top * -1;
  12. if ( currentTop < scrollPos) {
  13. // Scrolling Up
  14. if (currentTop > 0 && mainNav.classList.contains('is-fixed')) {
  15. mainNav.classList.add('is-visible');
  16. } else {
  17. console.log(123);
  18. mainNav.classList.remove('is-visible', 'is-fixed');
  19. }
  20. } else {
  21. // Scrolling Down
  22. mainNav.classList.remove(['is-visible']);
  23. if (currentTop > headerHeight && !mainNav.classList.contains('is-fixed')) {
  24. mainNav.classList.add('is-fixed');
  25. }
  26. }
  27. scrollPos = currentTop;
  28. });
  29. })
  30.  
Advertisement
Add Comment
Please, Sign In to add comment