Advertisement
afsarwebdev

JS-double header shrink and remove on header

Jul 29th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. //HTML:
  2. <div id="pagetop">
  3. header
  4. <div id="menu">Menu system</div>
  5. </div>
  6. //CSS:
  7.  
  8. #pagetop {
  9. position: fixed;
  10. top: 0;
  11. width: 100%;
  12. height: 120px;
  13. background-color: #06c;
  14. color: #fff;
  15. font-size: 23px;
  16. padding-top: 50px;
  17. transition: 0.4s all;
  18. }
  19. #pagetop > #menu {
  20. position: absolute;
  21. bottom: 0px;
  22. width: 100%;
  23. background: #004A95;
  24. height: 50px;
  25. transition: 0.4s all;
  26. }
  27. .dummy {
  28. padding-top: 170px;
  29. }
  30. //JS
  31. var pagetop, menu, yPos;
  32.  
  33. function yScroll() {
  34. pagetop = document.getElementById('pagetop');
  35. menu = document.getElementById('menu');
  36. yPos = window.pageYOffset;
  37. if( yPos > 150 ) {
  38. pagetop.style.height = "36px";
  39. pagetop.style.paddingTop = "8px";
  40. menu.style.height = "0px";
  41. } else {
  42. pagetop.style.height = "120px";
  43. pagetop.style.paddingTop = "50px";
  44. menu.style.height = "50px";
  45. }
  46. }
  47.  
  48. window.addEventListener("scroll", yScroll);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement