main.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. Hyperspace by HTML5 UP
  3. html5up.net | @ajlkn
  4. Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
  5. */
  6. (function($) {
  7. skel.breakpoints({
  8. xlarge: '(max-width: 1680px)',
  9. large: '(max-width: 1280px)',
  10. medium: '(max-width: 980px)',
  11. small: '(max-width: 736px)',
  12. xsmall: '(max-width: 480px)'
  13. });
  14. $(function() {
  15. var $window = $(window),
  16. $body = $('body'),
  17. $sidebar = $('#sidebar');
  18. // Hack: Enable IE flexbox workarounds.
  19. if (skel.vars.IEVersion < 12)
  20. $body.addClass('is-ie');
  21. // Disable animations/transitions until the page has loaded.
  22. if (skel.canUse('transition'))
  23. $body.addClass('is-loading');
  24. $window.on('load', function() {
  25. window.setTimeout(function() {
  26. $body.removeClass('is-loading');
  27. }, 100);
  28. });
  29. // Forms.
  30. // Fix: Placeholder polyfill.
  31. $('form').placeholder();
  32. // Hack: Activate non-input submits.
  33. $('form').on('click', '.submit', function(event) {
  34. // Stop propagation, default.
  35. event.stopPropagation();
  36. event.preventDefault();
  37. // Submit form.
  38. $(this).parents('form').submit();
  39. });
  40. // Prioritize "important" elements on medium.
  41. skel.on('+medium -medium', function() {
  42. $.prioritize(
  43. '.important\\28 medium\\29',
  44. skel.breakpoint('medium').active
  45. );
  46. });
  47. // Sidebar.
  48. if ($sidebar.length > 0) {
  49. var $sidebar_a = $sidebar.find('a');
  50. $sidebar_a
  51. .addClass('scrolly')
  52. .on('click', function() {
  53. var $this = $(this);
  54. // External link? Bail.
  55. if ($this.attr('href').charAt(0) != '#')
  56. return;
  57. // Deactivate all links.
  58. $sidebar_a.removeClass('active');
  59. // Activate link *and* lock it (so Scrollex doesn't try to activate other links as we're scrolling to this one's section).
  60. $this
  61. .addClass('active')
  62. .addClass('active-locked');
  63. })
  64. .each(function() {
  65. var $this = $(this),
  66. id = $this.attr('href'),
  67. $section = $(id);
  68. // No section for this link? Bail.
  69. if ($section.length < 1)
  70. return;
  71. // Scrollex.
  72. $section.scrollex({
  73. mode: 'middle',
  74. top: '-20vh',
  75. bottom: '-20vh',
  76. initialize: function() {
  77. // Deactivate section.
  78. if (skel.canUse('transition'))
  79. $section.addClass('inactive');
  80. },
  81. enter: function() {
  82. // Activate section.
  83. $section.removeClass('inactive');
  84. // No locked links? Deactivate all links and activate this section's one.
  85. if ($sidebar_a.filter('.active-locked').length == 0) {
  86. $sidebar_a.removeClass('active');
  87. $this.addClass('active');
  88. }
  89. // Otherwise, if this section's link is the one that's locked, unlock it.
  90. else if ($this.hasClass('active-locked'))
  91. $this.removeClass('active-locked');
  92. }
  93. });
  94. });
  95. }
  96. // Scrolly.
  97. $('.scrolly').scrolly({
  98. speed: 1000,
  99. offset: function() {
  100. // If <=large, >small, and sidebar is present, use its height as the offset.
  101. if (skel.breakpoint('large').active
  102. && !skel.breakpoint('small').active
  103. && $sidebar.length > 0)
  104. return $sidebar.height();
  105. return 0;
  106. }
  107. });
  108. // Spotlights.
  109. $('.spotlights > section')
  110. .scrollex({
  111. mode: 'middle',
  112. top: '-10vh',
  113. bottom: '-10vh',
  114. initialize: function() {
  115. // Deactivate section.
  116. if (skel.canUse('transition'))
  117. $(this).addClass('inactive');
  118. },
  119. enter: function() {
  120. // Activate section.
  121. $(this).removeClass('inactive');
  122. }
  123. })
  124. .each(function() {
  125. var $this = $(this),
  126. $image = $this.find('.image'),
  127. $img = $image.find('img'),
  128. x;
  129. // Assign image.
  130. $image.css('background-image', 'url(' + $img.attr('src') + ')');
  131. // Set background position.
  132. if (x = $img.data('position'))
  133. $image.css('background-position', x);
  134. // Hide <img>.
  135. $img.hide();
  136. });
  137. // Features.
  138. if (skel.canUse('transition'))
  139. $('.features')
  140. .scrollex({
  141. mode: 'middle',
  142. top: '-20vh',
  143. bottom: '-20vh',
  144. initialize: function() {
  145. // Deactivate section.
  146. $(this).addClass('inactive');
  147. },
  148. enter: function() {
  149. // Activate section.
  150. $(this).removeClass('inactive');
  151. }
  152. });
  153. });
  154. })(jQuery);