Guest User

Untitled

a guest
Nov 20th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. /* Optional script description */
  2.  
  3. $().ready(function() {
  4. appFront.init();
  5. });
  6.  
  7. // Popup youtube video
  8. $(document).ready(function () {
  9. $('.popup-youtube, .popup-vimeo, .popup-gmaps').magnificPopup({
  10. disableOn: 700,
  11. type: 'iframe',
  12. mainClass: 'mfp-fade',
  13. removalDelay: 160,
  14. preloader: false,
  15.  
  16. fixedContentPos: false
  17. });
  18. });
  19.  
  20. /**
  21. * Define JS object namespace
  22. */
  23. var appFront = (function() {
  24.  
  25. return {
  26.  
  27. /**
  28. *
  29. */
  30. init: function() {
  31. this.bindScrollTo();
  32. this.navScroll();
  33. this.modalInit();
  34. this.mobileMenu();
  35. this.mobileMenuClick();
  36. },
  37.  
  38. /**
  39. *
  40. */
  41. bindScrollTo: function() {
  42.  
  43. // Scroll to
  44. $(".scroll-to").click(function(evn){
  45. evn.preventDefault();
  46. var ww = window.innerWidth;
  47.  
  48. var offset = 0;
  49.  
  50. if ($(this).data("offset")) {
  51. offset = $(this).data("offset");
  52. } else {
  53. offset = 0;
  54. }
  55.  
  56. if (ww > 1024) {
  57. offset += $(".nav").height() - 20;
  58. }
  59.  
  60. if ($(this).data("href")) {
  61. var href = $(this).data("href");
  62. $('html,body').scrollTo(href, href, offset);
  63. } else {
  64. $('html,body').scrollTo(this.hash, this.hash, offset);
  65. }
  66.  
  67. });
  68. },
  69.  
  70. /**
  71. *
  72. */
  73. navScroll: function() {
  74. var prevScrollpos = window.pageYOffset;
  75. var ww = window.innerWidth;
  76.  
  77. if (ww > 1024) {
  78. checkNavPosition();
  79.  
  80. window.onscroll = function() {
  81. checkNavPosition();
  82. }
  83. }
  84.  
  85. function checkNavPosition() {
  86. var currentScrollPos = window.pageYOffset;
  87. var nav = $(".nav");
  88. var headerH = $(".header").height();
  89.  
  90. if (prevScrollpos > (headerH - 120)) {
  91. nav.addClass("nav--fixed");
  92. nav.removeClass("nav--hide");
  93. } else if (prevScrollpos > 200) {
  94. nav.addClass("nav--hide");
  95. nav.removeClass("nav--fixed");
  96. } else {
  97. nav.removeClass("nav--hide");
  98. nav.removeClass("nav--fixed");
  99. }
  100.  
  101. //console.log(prevScrollpos);
  102. //console.log("headerH: " + headerH);
  103.  
  104. // DeBounce MAC
  105. if (prevScrollpos <= 200) {
  106. nav.removeClass("nav--hide");
  107. nav.removeClass("nav--fixed");
  108. }
  109.  
  110. prevScrollpos = currentScrollPos;
  111. }
  112.  
  113.  
  114. },
  115.  
  116. /**
  117. *
  118. */
  119. mobileMenu: function() {
  120. $('.nav__mobile').on("click tap", function() {
  121. $('.nav').toggleClass('nav--show');
  122. })
  123. },
  124.  
  125. /**
  126. *
  127. */
  128. mobileMenuClick: function() {
  129. var ww = window.innerWidth;
  130.  
  131. if (ww <= 1024) {
  132. $('.nav__link').on("click tap", function() {
  133. $('.nav').toggleClass('nav--show');
  134. })
  135. }
  136. },
  137.  
  138. /**
  139. *
  140. */
  141. modalInit: function() {
  142.  
  143. $('.button').click(function () {
  144. var $btn = $(this);
  145. var id = $btn.data('id');
  146.  
  147. $(id).addClass('active');
  148. $(id).find('.modal').addClass('active');
  149.  
  150. });
  151.  
  152. $('.close-modal').click(function () {
  153. var $this = $(this);
  154.  
  155. $this.parent().removeClass('active');
  156. $this.parent().parent().removeClass('active');
  157. });
  158.  
  159. $('.modal-overlay').click(function (e) {
  160. //console.log(e.target);
  161. var modal = $(this);
  162.  
  163. if (e.target === this) {
  164. modal.removeClass('active');
  165. modal.children().removeClass('active');
  166. }
  167. });
  168.  
  169. }
  170. }
  171.  
  172. })();
Add Comment
Please, Sign In to add comment