navbar_hideable.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Hideable navbar
  4. *
  5. * Demo JS code for navbar_hideable.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var NavbarHideable = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Headroom.js
  15. var _componentHeadroom = function() {
  16. if (typeof Headroom == 'undefined') {
  17. console.warn('Warning - headroom.min.js is not loaded.');
  18. return;
  19. }
  20. // Define elements
  21. var navbarTop = document.querySelector('.navbar-slide-top'),
  22. navbarBottom = document.querySelector('.navbar-slide-bottom');
  23. //
  24. // Top navbar
  25. //
  26. if (navbarTop) {
  27. // Construct an instance of Headroom, passing the element
  28. var headroomTop = new Headroom(navbarTop, {
  29. offset: navbarTop.offsetHeight,
  30. tolerance: {
  31. up: 10,
  32. down: 10
  33. },
  34. onUnpin : function() {
  35. $('.headroom').find('.show').removeClass('show');
  36. }
  37. });
  38. // Initialise
  39. headroomTop.init();
  40. }
  41. //
  42. // Bottom navbar
  43. //
  44. if (navbarBottom) {
  45. // Construct an instance of Headroom, passing the element
  46. var headroomBottom = new Headroom(navbarBottom, {
  47. offset: navbarBottom.offsetHeight,
  48. tolerance: {
  49. up: 10,
  50. down: 10
  51. },
  52. onUnpin : function() {
  53. $('.headroom').find('.show').removeClass('show');
  54. }
  55. });
  56. // Initialise
  57. headroomBottom.init();
  58. }
  59. };
  60. //
  61. // Return objects assigned to module
  62. //
  63. return {
  64. init: function() {
  65. _componentHeadroom();
  66. }
  67. }
  68. }();
  69. // Initialize module
  70. // ------------------------------
  71. document.addEventListener('DOMContentLoaded', function() {
  72. NavbarHideable.init();
  73. });