init.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. jQuery(document).ready(function($) {
  2. $('.nav-toggle').on( 'click', function() {
  3. $( this ).toggleClass( 'active' );
  4. });
  5. var headerHeight = $('.navbar').height();
  6. $(window).on('scroll', { previousTop: 0 },
  7. function() {
  8. var currentTop = $(window).scrollTop();
  9. if (currentTop < this.previousTop) {
  10. if (currentTop > 0 && $('.navbar').hasClass('fixed')) {
  11. $('.navbar').addClass('visible');
  12. } else {
  13. $('.navbar').removeClass('visible fixed');
  14. }
  15. } else {
  16. $('.navbar').removeClass('visible');
  17. if (currentTop > headerHeight && !$('.navbar').hasClass('fixed')) $('.navbar').addClass('fixed');
  18. }
  19. this.previousTop = currentTop;
  20. });
  21. var commentsDiv = $('#comments');
  22. if (commentsDiv.length) {
  23. $(commentsDiv).hide();
  24. $('.toggle-comments').on('click', function(e) {
  25. e.preventDefault();
  26. $(commentsDiv).toggle('slow', function() {
  27. var anchor = $('.toggle-comments');
  28. var anchorText = anchor.text() === 'Hide Comments' ? 'Show Comments' : 'Hide Comments';
  29. $(anchor).text(anchorText);
  30. });
  31. });
  32. }
  33. });