Advertisement
fznuk

Untitled

Jan 10th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // When the user scrolls the page, execute myFunction
  3. window.onscroll = function() {scrollFunction()};
  4.  
  5. // Get the header ID class + Logo class
  6. var header = document.getElementById("headbrand");
  7. var header2 = document.getElementById("header");
  8.  
  9. // Get the offset position of the navbar
  10. var sticky = header.offsetTop;
  11.  
  12. // Add the sticky and headbrand class to the header and logo when you reach its scroll position. Remove "sticky" and restore logo size when you leave the scroll position
  13. function scrollFunction() {
  14.   if (window.pageYOffset  >= sticky) {
  15.     header.classList.add('headlogo','img'); header2.classList.add("sticky");
  16.   } else {
  17.     header.classList.remove('headlogo','img'); header2.classList.remove("sticky");
  18.   }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement