Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <style type="text/css">
  2.  
  3. nav {
  4. position:absolute;
  5. bottom:0;
  6. left:0;
  7. background-color:#eee;
  8. box-sizing:border-box;
  9. width:100%;
  10. padding:20px;
  11. }
  12.  
  13. nav.fixed-position {
  14. position:fixed;
  15. top:0;
  16. bottom:initial;
  17. }
  18.  
  19. </style>
  20.  
  21. <div>
  22.  
  23. <div id="hero">
  24.  
  25. <nav id="nav-menu">
  26. Your nav here
  27. </nav>
  28.  
  29. </div>
  30.  
  31. <section style="height:2000px;">
  32.  
  33. content
  34.  
  35. </section>
  36.  
  37. </div>
  38.  
  39. <script type="text/javascript">
  40.  
  41. var hero = document.getElementById('hero'),
  42. nav = document.getElementById("nav-menu"),
  43. viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
  44. navOffsetTop = nav.offsetTop;
  45.  
  46. hero.style.height = viewPortHeight + 'px';
  47.  
  48. var hasScrolled = function() {
  49.  
  50. var fromTop = document.body.scrollTop || document.documentElement.scrollTop || 0;
  51.  
  52. if (navOffsetTop < fromTop) {
  53. nav.classList.add('fixed-position');
  54. } else {
  55. nav.classList.remove('fixed-position');
  56. }
  57.  
  58. }
  59.  
  60. window.addEventListener('scroll', hasScrolled);
  61.  
  62. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement