back-top.js 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* global shoreditchButtonTitle */
  2. ( function( $ ) {
  3. var button, resizeTimer;
  4. button = $( '<button />', {
  5. 'class': 'back-top',
  6. 'aria-hidden': true,
  7. text: shoreditchButtonTitle.desc
  8. } );
  9. function createButton() {
  10. if ( $( window ).innerWidth() < 768 ) {
  11. if ( 0 === $( '.back-top' ).length ) {
  12. $( '#page' ).after( button );
  13. }
  14. $( '.back-top' ).on( 'click', function() {
  15. $( 'html, body' ).animate( {
  16. scrollTop: 0
  17. }, 250 );
  18. } );
  19. } else {
  20. $( '.back-top' ).remove();
  21. }
  22. }
  23. $( document ).ready( function() {
  24. $( window )
  25. .on( 'load.shoreditch', createButton )
  26. .on( 'resize.shoreditch', function() {
  27. clearTimeout( resizeTimer );
  28. resizeTimer = setTimeout( createButton, 300 );
  29. } )
  30. .on( 'scroll.shoreditch', function() {
  31. if ( $( window ).scrollTop() >= $( window ).innerHeight() ) {
  32. $( '.back-top' ).slideDown( 250 );
  33. } else {
  34. $( '.back-top' ).slideUp( 250 );
  35. }
  36. } );
  37. } );
  38. } )( jQuery );