background-fix.js 844 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. ( function( $ ) {
  2. /**
  3. * Test if an iOS device.
  4. */
  5. function checkiOS() {
  6. return /iPad|iPhone|iPod/.test(navigator.userAgent) && ! window.MSStream;
  7. }
  8. /*
  9. * Test if background-attachment: fixed is supported.
  10. * @link http://stackoverflow.com/questions/14115080/detect-support-for-background-attachment-fixed
  11. */
  12. function supportsFixedBackground() {
  13. var el = document.createElement('div'),
  14. isSupported;
  15. try {
  16. if ( ! ( 'backgroundAttachment' in el.style ) || checkiOS() ) {
  17. return false;
  18. }
  19. el.style.backgroundAttachment = 'fixed';
  20. isSupported = ( 'fixed' === el.style.backgroundAttachment );
  21. return isSupported;
  22. }
  23. catch (e) {
  24. return false;
  25. }
  26. }
  27. $( document ).ready( function() {
  28. if ( false === supportsFixedBackground() ) {
  29. $( 'body' ).addClass( 'no-background-fixed' );
  30. }
  31. } );
  32. } )( jQuery );