frontpage.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * File frontpage.js.
  3. *
  4. * Handles scrolling navigation for the front-page.php template
  5. */
  6. ( function( $ ) {
  7. $( document ).ready( function() {
  8. var navHeight = $( '.header-wrapper' ).outerHeight();
  9. $( '.panel-navigation a' ).on( 'click', function( e ) {
  10. e.preventDefault();
  11. var panel = $( this ).attr( 'href' );
  12. $( 'body, html' ).animate( {
  13. scrollTop: $( panel ).offset().top - navHeight - 30,
  14. }, 1000 );
  15. });
  16. });
  17. $( document ).on ( 'scroll', function( e ) {
  18. e.preventDefault();
  19. var navHeight = $( '.header-wrapper' ).outerHeight();
  20. var currentPosition = window.pageYOffset;
  21. var topPanel = $( 'body' ).offset().top;
  22. var counter = 1;
  23. if ( currentPosition >= topPanel ) {
  24. $( '.panel-navigation a' ).removeClass( 'active' );
  25. $( '.panel-navigation a.panel0' ).addClass( 'active' );
  26. }
  27. $( '.panel' ).each( function() {
  28. var panelPosition = parseInt( $( this ).offset().top ) - navHeight - 30;
  29. if ( currentPosition >= panelPosition ) {
  30. $( '.panel-navigation a' ).removeClass( 'active' );
  31. $( '.panel-navigation a.panel' + counter ).addClass( 'active' );
  32. }
  33. counter++;
  34. } );
  35. });
  36. } )( jQuery );