script.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. $(document).ready(function() {
  2. new WOW({
  3. mobile: false,
  4. animateClass: 'animate__animated',
  5. }).init();
  6. setTimeout(function() {
  7. $('.prelodaer-wrap').fadeOut('slow');
  8. }, 4500);
  9. //Ajax Form Send START
  10. $('#contact-form').on('submit', function() {
  11. var th = $(this);
  12. $.ajax({
  13. type: 'POST',
  14. url: 'mail.php',
  15. data: th.serialize(),
  16. success: function() {
  17. th.trigger('reset');
  18. $('.input-field').removeClass('is-active');
  19. $.magnificPopup.open({
  20. items: {
  21. src: '<div class="form-alert"><p>Your application has been successfully sent. <br> Expect a call!</p></div>',
  22. type: 'inline'
  23. }
  24. });
  25. },
  26. error: function() {
  27. th.trigger('reset');
  28. $('.input-field').removeClass('is-active');
  29. $.magnificPopup.open({
  30. items: {
  31. src: '<div class="form-alert"><p>An error occurred, please try again</p></div>',
  32. type: 'inline'
  33. }
  34. });
  35. }
  36. });
  37. return false;
  38. });
  39. //Ajax Form Send END
  40. // Banner START
  41. const swiperBanner = new Swiper('.swiper-banner', {
  42. speed: 800,
  43. spaceBetween: 100,
  44. effect: 'fade',
  45. fadeEffect: {
  46. crossFade: true
  47. },
  48. navigation: {
  49. nextEl: '.swiper-banner .swiper-button-next',
  50. prevEl: '.swiper-banner .swiper-button-prev',
  51. },
  52. scrollbar: {
  53. el: '.swiper-banner .swiper-scrollbar',
  54. enabled: true,
  55. draggable: true
  56. },
  57. });
  58. // Banner END
  59. // Menu START
  60. $('body').on('click', '.hamburger-button', function(e) {
  61. e.preventDefault();
  62. hamburgerButton = $('.hamburger-button');
  63. hamburgerMenuWrap = $('.menu-wrap');
  64. hamburgerMenuItem = $('.menu-nav');
  65. hamburgerMenuWrap.addClass('menu-active');
  66. hamburgerMenuItem.addClass('menu-item-active');
  67. menuOverlay = $('.menu-overlay');
  68. menuOverlay.addClass('menu-overlay__active');
  69. });
  70. $(document).on('mouseup', function(e) {
  71. e.preventDefault();
  72. menuClose = $('.menu-close');
  73. hamburgerMenuWrap = $('.menu-wrap');
  74. hamburgerMenuItem = $('.menu-nav');
  75. menuOverlay = $('.menu-overlay');
  76. if (!hamburgerMenuWrap.is(e.target) && hamburgerMenuWrap.has(e.target).length === 0) {
  77. hamburgerMenuWrap.removeClass('menu-active');
  78. hamburgerMenuItem.removeClass('menu-item-active');
  79. menuOverlay.removeClass('menu-overlay__active');
  80. }
  81. menuClose.on('mousedown', function() {
  82. hamburgerMenuWrap.removeClass('menu-active');
  83. hamburgerMenuItem.removeClass('menu-item-active');
  84. menuOverlay.removeClass('menu-overlay__active');
  85. });
  86. });
  87. // Menu END
  88. // Contact START
  89. $('.input-field input, textarea').on('input', function() {
  90. var inputValue = $(this).val();
  91. var inputpParent = $(this).parent('.input-field');
  92. if (inputValue.length > 0) {
  93. inputpParent.addClass('is-active');
  94. } else {
  95. inputpParent.removeClass('is-active');
  96. }
  97. });
  98. // Contact END
  99. // Gallery Single page START
  100. $('.grid-single .grid-item img').parazoom({
  101. customCursorIcon: 'images/magnify.svg',
  102. customCursorSize: '30px',
  103. transitionTime: '1s',
  104. transitionTimeLeave: '1s'
  105. });
  106. var $grid = $('.grid-single').masonry({
  107. itemSelector: '.grid-single .grid-item',
  108. percentPosition: true,
  109. columnWidth: '.grid-single .grid-sizer'
  110. });
  111. $grid.imagesLoaded().progress( function() {
  112. $grid.masonry({
  113. gutter: 15
  114. });
  115. });
  116. $('.grid-single .grid-item a').magnificPopup({
  117. type:'image',
  118. removalDelay: 500,
  119. gallery: {
  120. enabled: true
  121. },
  122. callbacks: {
  123. beforeOpen: function() {
  124. this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
  125. this.st.mainClass = this.st.el.attr('data-effect');
  126. }
  127. },
  128. });
  129. // Gallery Single page END
  130. // Album page START
  131. function albumMasonry() {
  132. var $gridAlbum = $('.grid-album').masonry({
  133. itemSelector: '.grid-album .grid-item',
  134. percentPosition: true,
  135. columnWidth: '.grid-album .grid-sizer'
  136. });
  137. $gridAlbum.imagesLoaded().progress( function() {
  138. $gridAlbum.masonry({
  139. gutter: 20
  140. });
  141. });
  142. }
  143. albumMasonry();
  144. var bLazy = new Blazy();
  145. $('.album-tab a').on('click', function(e) {
  146. e.preventDefault();
  147. var href = $(this).attr('href');
  148. $('.album-tab a').removeClass('is-active');
  149. $(this).addClass('is-active');
  150. $('.grid-album').removeClass('is-active');
  151. $(href).addClass('is-active');
  152. $(href).addClass('animate__animated animate__slideInUp');
  153. $('.grid-album.is-active:not(' + href + ')').removeClass('animate__animated animate__slideInUp');
  154. albumMasonry();
  155. });
  156. // Album page END
  157. // Settings START
  158. $('.settings-btn').on('click', function() {
  159. var settings = $('.settings-wrap');
  160. settings.toggleClass('is-active');
  161. });
  162. var savedColor = localStorage.getItem('boxColor');
  163. if (savedColor) {
  164. $(':root').css('--color-def', savedColor);
  165. }
  166. $('.settings-color-item').on('click', function() {
  167. var color = $(this).css('background-color');
  168. $('.settings-color-item').css('border-color', '#fff');
  169. $(this).css('border-color', color);
  170. $(':root').css('--color-def', color);
  171. localStorage.setItem('boxColor', color);
  172. });
  173. // Settings END
  174. // 当鼠标经过 li 元素时
  175. // $('.menu-nav li').hover(
  176. // function() {
  177. // // 显示子菜单
  178. // $(this).find('.menu-nav-son').stop(true, true).slideDown(200);
  179. // },
  180. // function() {
  181. // // 隐藏子菜单
  182. // $(this).find('.menu-nav-son').stop(true, true).slideUp(0);
  183. // }
  184. // );
  185. $('.menu-nav li').hover(
  186. function () {
  187. // 显示当前 li 的子菜单
  188. $(this).find('.menu-nav-son').stop(true, true).slideDown(200);
  189. }
  190. );
  191. // 当鼠标离开 .menu-nav ul 时
  192. $('.menu-nav').mouseleave(function () {
  193. // 隐藏所有子菜单
  194. $('.menu-nav-son').stop(true, true).slideUp(200);
  195. });
  196. // 创建全屏遮罩层
  197. $('.album-thumb').on('click', function (event) {
  198. // 如果点击的是 download-icon,阻止后续代码执行
  199. if ($(event.target).closest('.download-icon').length) {
  200. return;
  201. }
  202. // 获取当前点击的 .album-thumb 的父级 .grid-album 元素
  203. var $parentAlbum = $(this).closest('.grid-album');
  204. // 获取当前父级下所有 .album-thumb img 的 src
  205. var imageSrcArray = [];
  206. $parentAlbum.find('.album-thumb img').each(function () {
  207. console.log($(this).attr('class'));
  208. imageSrcArray.push($(this).attr('src'));
  209. });
  210. // 获取当前点击图片在数组中的索引
  211. var $albumThumbs = $parentAlbum.find('.album-thumb');
  212. var currentImageIndex = $albumThumbs.index(this);
  213. // console.log(currentImageIndex);
  214. const $fullscreenMask = $('<div>').addClass('fullscreen-mask');
  215. const $fullscreenImg = $('<img>').attr('src', imageSrcArray[currentImageIndex]);
  216. const $btnLeft = $('<div>').addClass('fullscreen-btn fullscreen-btn-left').html('&lt;');
  217. const $btnRight = $('<div>').addClass('fullscreen-btn fullscreen-btn-right').html('&gt;');
  218. $fullscreenMask.append($fullscreenImg, $btnLeft, $btnRight);
  219. // 将遮罩层添加到 body
  220. $('body').append($fullscreenMask);
  221. setTimeout(function () {
  222. $fullscreenMask.addClass('active');
  223. }, 10);
  224. // 点击遮罩层时关闭
  225. $fullscreenMask.on('click', function (e) {
  226. if (!$(e.target).is($btnLeft) && !$(e.target).is($btnRight)) {
  227. $fullscreenMask.removeClass('active');
  228. setTimeout(function () {
  229. $fullscreenMask.remove();
  230. }, 300);
  231. }
  232. });
  233. // 点击左按钮显示上一张图片
  234. $btnLeft.on('click', function () {
  235. currentImageIndex--;
  236. if (currentImageIndex < 0) {
  237. currentImageIndex = imageSrcArray.length - 1;
  238. }
  239. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  240. });
  241. // 点击右按钮显示下一张图片
  242. $btnRight.on('click', function () {
  243. currentImageIndex++;
  244. if (currentImageIndex >= imageSrcArray.length) {
  245. currentImageIndex = 0;
  246. }
  247. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  248. });
  249. });
  250. const $overlay = $('#overlay');
  251. const $videoPlayer = $('#videoPlayer');
  252. const $closeBtn = $('#closeBtn');
  253. const $videoBtns = $('.video-btn');
  254. // 点击播放按钮
  255. $videoBtns.on('click', function() {
  256. const videoSrc = $(this).data('src'); // 获取 data-src 属性
  257. $videoPlayer.attr('src', videoSrc); // 设置视频源
  258. $overlay.css('display', 'flex'); // 显示遮罩层
  259. });
  260. // 点击关闭按钮
  261. $closeBtn.on('click', function() {
  262. $videoPlayer[0].pause(); // 暂停视频
  263. $videoPlayer.attr('src', ''); // 清空视频源
  264. $overlay.hide(); // 隐藏遮罩层
  265. });
  266. // 点击遮罩层关闭
  267. $overlay.on('click', function(event) {
  268. if (event.target === $overlay[0]) { // 判断是否点击的是遮罩层本身
  269. $videoPlayer[0].pause(); // 暂停视频
  270. $videoPlayer.attr('src', ''); // 清空视频源
  271. $overlay.hide(); // 隐藏遮罩层
  272. }
  273. });
  274. // 为 .log-date 绑定点击事件
  275. $('.log-date').on('click', function() {
  276. // 找到当前 .log-date 的同级 .log-line 元素
  277. $(this).siblings('.log-line').toggleClass('active');
  278. });
  279. });