Advertisement
afsarwebdev

Header scroll page

Sep 3rd, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Header shrink after scroll</title>
  6. <style media="screen">
  7. body{margin: 0; text-align: center; background: #6fdc6f;}
  8. #pagetop {position: fixed; top: 0px; width: 100%;height: 120px; background: #32cd32; color: white; padding: 20px; transition: height 0.3s linear 0s; overflow: hidden;}
  9. #pagetop > #menu {
  10. position: absolute; bottom: 0px; left: 0px; width: 100%; background: #238f23; height: 50px; transition: height 0.3s linear 0s;
  11. }
  12. .wrapper {margin-top: 230px}
  13. </style>
  14. <script type="text/javascript">
  15.  
  16. var pagetop, menu, yPos;
  17. function yScroll() {
  18. pagetop = document.getElementById('pagetop');
  19. menu = document.getElementById('menu');
  20. yPos = window.pageYOffset;
  21. if(yPos > 150) {
  22. pagetop.style.height = "36px";
  23. pagetop.style.paddingTop = "8px";
  24. menu.style.height = "0px";
  25. }
  26. else {
  27. pagetop.style.height = "120px";
  28. pagetop.style.paddingTop = "50px";
  29. menu.style.height = "50px";
  30. }
  31. }
  32. window.addEventListener('scroll', yScroll);
  33.  
  34. </script>
  35. </head>
  36. <body>
  37. <div id="pagetop">
  38. Header
  39. <div id="menu">
  40. Menu here
  41. </div>
  42. </div>
  43. <div class="wrapper">
  44. <script type="text/javascript">
  45. for(var i = 0; i < 60; i++){
  46. document.write("<h1>"+ (i+1) +".This dummy text... </h1>");
  47. }
  48. </script>
  49. </div>
  50. </body>
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement