header.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. (function ($) {
  2. "use strict"; // Start of use strict
  3. // Floating label headings for the contact form
  4. $("body").on("input propertychange", ".floating-label-form-group", function (e) {
  5. $(this).toggleClass("floating-label-form-group-with-value", !!$(e.target).val());
  6. }).on("focus", ".floating-label-form-group", function () {
  7. $(this).addClass("floating-label-form-group-with-focus");
  8. }).on("blur", ".floating-label-form-group", function () {
  9. $(this).removeClass("floating-label-form-group-with-focus");
  10. });
  11. // Show the navbar when the page is scrolled up
  12. var MQL = 992;
  13. //primary navigation slide-in effect
  14. if ($(window).width() > MQL) {
  15. var headerHeight = $('#mainNav').height();
  16. $(window).on('scroll', {
  17. previousTop: 0
  18. },
  19. function () {
  20. var currentTop = $(window).scrollTop();
  21. //check if user is scrolling up
  22. if (currentTop < this.previousTop) {
  23. //if scrolling up...
  24. if (currentTop > 0 && $('#mainNav').hasClass('is-fixed')) {
  25. $('#mainNav').addClass('is-visible');
  26. } else {
  27. $('#mainNav').removeClass('is-visible is-fixed');
  28. }
  29. } else if (currentTop > this.previousTop) {
  30. //if scrolling down...
  31. $('#mainNav').removeClass('is-visible');
  32. if (currentTop > headerHeight && !$('#mainNav').hasClass('is-fixed')) $('#mainNav').addClass('is-fixed');
  33. }
  34. this.previousTop = currentTop;
  35. });
  36. }
  37. })(jQuery); // End of use strict
  38. $('.search-button').click(function () {
  39. $(this).parent().toggleClass('open');
  40. });