info-nav.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ( function( $ ) {
  2. 'use strict';
  3. var $doc = $( document );
  4. var $win = $( window );
  5. var mediaQueries = {
  6. xs: {
  7. from: 0,
  8. to: 543
  9. },
  10. sm: {
  11. from: 544,
  12. to: 767
  13. },
  14. md: {
  15. from: 768,
  16. to: 991
  17. },
  18. lg: {
  19. from: 992,
  20. to: 1199
  21. },
  22. xl: {
  23. from: 1200,
  24. to: 'all'
  25. }
  26. };
  27. $doc.ready( function( $ ) {
  28. var $header = $( '#header' );
  29. var $heroBlock = $( '.info-header' );
  30. var ticking = false;
  31. function update() {
  32. var el = document.documentElement,
  33. body = document.getElementsByTagName( 'body' )[0],
  34. x = window.innerWidth || el.clientWidth || body.clientWidth,
  35. y = window.innerHeight || el.clientHeight || body.clientHeight;
  36. var wScrollTop = $win.scrollTop();
  37. if ( $header.hasClass( 'is-fixed' ) ) {
  38. $header.toggleClass( 'is-small', wScrollTop > $header.outerHeight() );
  39. }
  40. var heroHeight = $heroBlock.find( '.container' ).outerHeight();
  41. if ( wScrollTop < y && x > mediaQueries.md.from ){
  42. $heroBlock.css( {
  43. opacity: Math.max( Math.min( ( heroHeight - wScrollTop ) / ( heroHeight ), 1 ), 0 )
  44. } );
  45. }
  46. var section = document.querySelector( '.features.dark-theme' );
  47. if ( section ) {
  48. $header.toggleClass( 'is-light', section.getBoundingClientRect().top < 40 );
  49. }
  50. ticking = false;
  51. }
  52. function onScroll() {
  53. requestTick();
  54. }
  55. function requestTick() {
  56. if ( ! ticking ) {
  57. requestAnimationFrame( update );
  58. }
  59. ticking = true;
  60. }
  61. $win
  62. .scroll( onScroll )
  63. .resize( onScroll );
  64. onScroll();
  65. } );
  66. // $doc.ready( function( $ ) {
  67. // var $header = $( '#header' );
  68. // var $heroBlock = $( '.info-li-bo' );
  69. // var ticking = false;
  70. // function update() {
  71. // var el = document.documentElement,
  72. // body = document.getElementsByTagName( 'body' )[0],
  73. // x = window.innerWidth || el.clientWidth || body.clientWidth,
  74. // y = window.innerHeight || el.clientHeight || body.clientHeight;
  75. // var wScrollTop = $win.scrollTop();
  76. // if ( $header.hasClass( 'is-fixed' ) ) {
  77. // $header.toggleClass( 'is-small', wScrollTop > $header.outerHeight() );
  78. // }
  79. // var heroHeight = $heroBlock.find( '.container' ).outerHeight();
  80. // if ( wScrollTop < y && x > mediaQueries.md.from ){
  81. // $heroBlock.css( {
  82. // opacity: Math.max( Math.min( ( heroHeight - wScrollTop ) / ( heroHeight ), 1 ), 0 )
  83. // } );
  84. // }
  85. // var section = document.querySelector( '.features.dark-theme' );
  86. // if ( section ) {
  87. // $header.toggleClass( 'is-light', section.getBoundingClientRect().top < 40 );
  88. // }
  89. // ticking = false;
  90. // }
  91. // function onScroll() {
  92. // requestTick();
  93. // }
  94. // function requestTick() {
  95. // if ( ! ticking ) {
  96. // requestAnimationFrame( update );
  97. // }
  98. // ticking = true;
  99. // }
  100. // $win
  101. // .scroll( onScroll )
  102. // .resize( onScroll );
  103. // onScroll();
  104. // } );
  105. } ) ( jQuery );