init.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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', {
  7. previousTop: 0
  8. },
  9. function() {
  10. var currentTop = $(window).scrollTop();
  11. if (currentTop < this.previousTop) {
  12. if (currentTop > 0 && $('.navbar').hasClass('fixed')) {
  13. $('.navbar').addClass('visible');
  14. } else {
  15. $('.navbar').removeClass('visible fixed');
  16. }
  17. } else {
  18. $('.navbar').removeClass('visible');
  19. if (currentTop > headerHeight && !$('.navbar').hasClass('fixed')) $('.navbar').addClass('fixed');
  20. }
  21. this.previousTop = currentTop;
  22. });
  23. var commentsDiv = $('#comments');
  24. if (commentsDiv.length) {
  25. $(commentsDiv).hide();
  26. $('.toggle-comments').on('click', function(e) {
  27. e.preventDefault();
  28. $(commentsDiv).toggle('slow', function() {
  29. var anchor = $('.toggle-comments');
  30. var anchorText = anchor.text() == 'Hide Comments' ? 'Show Comments' : 'Hide Comments';
  31. $(anchor).text(anchorText);
  32. });
  33. });
  34. }
  35. });