main.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. (function ($) {
  2. "use strict";
  3. //--------------------------------------------------
  4. // Preloader
  5. //--------------------------------------------------
  6. $(window).on('load', function () {
  7. $('.preloader').fadeOut('slow');
  8. RevealLoad();
  9. startAnim();
  10. $('.preloader').removeClass()
  11. })
  12. //--------------------------------------------------
  13. // Animation Start
  14. //--------------------------------------------------
  15. function startAnim() {
  16. TweenMax.from('.logo', 1, {
  17. y: '100',
  18. autoAlpha: 0,
  19. delay: '.3',
  20. ease: Power4.easeInOut,
  21. })
  22. TweenMax.from('.toggle-btn', 1, {
  23. y: '100',
  24. delay: '.3',
  25. autoAlpha: 0,
  26. ease: Power4.easeInOut,
  27. })
  28. TweenMax.from('.bg-right', 1, {
  29. x: 100,
  30. ease: Power4.easeInOut,
  31. delay: '.3',
  32. })
  33. TweenMax.from('.bg-about', 1, {
  34. x: 100,
  35. ease: Power4.easeInOut,
  36. delay: '.3',
  37. })
  38. TweenMax.from('.scr', 1, {
  39. y: '100',
  40. ease: Power4.easeInOut,
  41. autoAlpha: 0,
  42. })
  43. TweenMax.from('.scrolls', 1, {
  44. y: '100',
  45. delay: 1,
  46. ease: Power4.easeInOut,
  47. autoAlpha: 0,
  48. })
  49. TweenMax.to('.menu', 0, {
  50. autoAlpha: 0,
  51. })
  52. }
  53. //--------------------------------------------------
  54. // Parralax
  55. //--------------------------------------------------
  56. var headermove = $('#headmove').get(0);
  57. var parallaxInstance = new Parallax(headermove, {
  58. relativeInput: true,
  59. scalarX: 14,
  60. hoverOnly: false,
  61. });
  62. //--------------------------------------------------
  63. // Web Load
  64. //--------------------------------------------------
  65. function RevealLoad() {
  66. var loadTL = new TimelineMax();
  67. var block1 = $('.block-1');
  68. var block2 = $('.block-2');
  69. var logo = $('.logo-load');
  70. loadTL
  71. .to(block1, 0.5, {
  72. height: '0',
  73. delay: '0'
  74. })
  75. .to(block2, 0.5, {
  76. height: '0',
  77. })
  78. .to(logo, 0, {
  79. autoAlpha: 0,
  80. delay: '-0.4',
  81. })
  82. loadTL.play();
  83. }
  84. function HideLoad() {
  85. var loadTL = new TimelineMax();
  86. var block1 = $('.block-1');
  87. var block2 = $('.block-2');
  88. var logo = $('.logo-load');
  89. loadTL
  90. .to(block1, 0.5, {
  91. height: '100%',
  92. delay: '0'
  93. })
  94. .to(block2, 0.5, {
  95. height: '100%',
  96. })
  97. .to(logo, 0, {
  98. autoAlpha: 1,
  99. delay: '-0.5'
  100. })
  101. loadTL.play();
  102. }
  103. //为点击事件专门做一个过渡动画方法
  104. function HideLoadClick() {
  105. var loadTL = new TimelineMax();
  106. var block1 = $('.block-1');
  107. var block2 = $('.block-2');
  108. var logo = $('.logo-load');
  109. loadTL
  110. .to(block1, 0.5, {
  111. height: '100%',
  112. delay: '0'
  113. })
  114. .to(block2, 0.5, {
  115. height: '100%',
  116. })
  117. .to(logo, 0, {
  118. autoAlpha: 1,
  119. delay: '-0.5'
  120. })
  121. loadTL.play();
  122. //设置一个定时器
  123. setTimeout(function () {
  124. RevealLoad();
  125. }, 5000);
  126. }
  127. $('.load-spiral').on('click', function (e) {
  128. e.preventDefault();
  129. setTimeout(function (url) {
  130. window.location = url;
  131. }, 1000, this.href);
  132. HideLoadClick();
  133. });
  134. //--------------------------------------------------
  135. // Animation on navbar scrolling background
  136. //--------------------------------------------------
  137. var wind = $(window);
  138. wind.on("scroll", function () {
  139. var bodyScroll = wind.scrollTop();
  140. if (bodyScroll > 300) {
  141. TweenMax.to('.scr', .5, {
  142. autoAlpha: 0,
  143. y: '100',
  144. })
  145. TweenMax.to('.scrolls', .5, {
  146. autoAlpha: 0,
  147. y: '100',
  148. })
  149. } else {
  150. TweenMax.to('.scr', 1, {
  151. autoAlpha: 1,
  152. y: '00',
  153. })
  154. TweenMax.to('.scrolls', .5, {
  155. autoAlpha: 1,
  156. y: '0',
  157. })
  158. }
  159. });
  160. $('.img-folio').on('mouseenter', function () {
  161. TweenMax.to(this, 0.4, {
  162. y: '-30',
  163. })
  164. });
  165. $('.img-folio').on('mouseleave', function () {
  166. TweenMax.to(this, 0.4, {
  167. y: '1',
  168. })
  169. });
  170. luxy.init({
  171. wrapper: '#spiral',
  172. wrapperSpeed: '0.07',
  173. });
  174. //--------------------------------------------------
  175. // Cursor
  176. //--------------------------------------------------
  177. var isMobile = false;
  178. if (/Android|webOS|iPhone|iPod|iPad|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
  179. $('html').addClass('touch');
  180. isMobile = true;
  181. } else {
  182. $('html').addClass('no-touch');
  183. isMobile = false;
  184. }
  185. var isMacLike = /(Mac)/i.test(navigator.platform);
  186. var cursor = {
  187. delay: 8,
  188. _x: 0,
  189. _y: 0,
  190. endX: (window.innerWidth / 2),
  191. endY: (window.innerHeight / 2),
  192. cursorVisible: true,
  193. cursorEnlarged: false,
  194. $cursor: document.querySelector('.cursor'),
  195. $cursor1: document.querySelector('.cursor1'),
  196. init: function () {
  197. // Set up element sizes
  198. this.cursorSize = this.$cursor.offsetWidth;
  199. this.cursor1Size = this.$cursor1.offsetWidth;
  200. this.setupEventListeners();
  201. this.animateDotOutline();
  202. this.cursorDrag();
  203. this.cursorExplore();
  204. this.cursorZoom();
  205. this.cursorNext();
  206. this.cursorPrev();
  207. },
  208. setupEventListeners: function () {
  209. var self = this;
  210. // Anchor hovering
  211. Array.prototype.slice.call(document.querySelectorAll(' .zoom-cursor, .hover-target')).forEach(function (el) {
  212. el.addEventListener('mouseover', function () {
  213. self.cursorEnlarged = true;
  214. self.toggleCursorSize();
  215. });
  216. el.addEventListener('mouseout', function () {
  217. self.cursorEnlarged = false;
  218. self.toggleCursorSize();
  219. });
  220. });
  221. document.addEventListener('mousemove', function (e) {
  222. // Show the cursor
  223. self.cursorVisible = true;
  224. self.toggleCursorVisibility();
  225. // Position the dot
  226. self.endX = e.clientX;
  227. self.endY = e.clientY;
  228. self.$cursor.style.top = self.endY + 'px';
  229. self.$cursor.style.left = self.endX + 'px';
  230. });
  231. // Hide/show cursor
  232. document.addEventListener('mouseenter', function (e) {
  233. self.cursorVisible = true;
  234. self.toggleCursorVisibility();
  235. self.$cursor.style.opacity = 1;
  236. self.$cursor1.style.opacity = 1;
  237. });
  238. document.addEventListener('mouseleave', function (e) {
  239. self.cursorVisible = true;
  240. self.toggleCursorVisibility();
  241. self.$cursor.style.opacity = 0;
  242. self.$cursor1.style.opacity = 0;
  243. });
  244. },
  245. animateDotOutline: function () {
  246. var self = this;
  247. self._x += (self.endX - self._x) / self.delay;
  248. self._y += (self.endY - self._y) / self.delay;
  249. self.$cursor1.style.top = self._y + 'px';
  250. self.$cursor1.style.left = self._x + 'px';
  251. requestAnimationFrame(this.animateDotOutline.bind(self));
  252. },
  253. toggleCursorSize: function () {
  254. var self = this;
  255. if (self.cursorEnlarged) {
  256. self.$cursor1.classList.add('expand');
  257. } else {
  258. self.$cursor1.classList.remove('expand');
  259. }
  260. },
  261. toggleCursorVisibility: function () {
  262. var self = this;
  263. if (self.cursorVisible) {
  264. self.$cursor.style.opacity = 1;
  265. self.$cursor1.style.opacity = 1;
  266. } else {
  267. self.$cursor.style.opacity = 0;
  268. self.$cursor1.style.opacity = 0;
  269. }
  270. },
  271. cursorDrag: function () {
  272. var self = this;
  273. $('.cursorDrag').on('mouseenter', function () {
  274. self.$cursor1.classList.add('drag', 'expand');
  275. });
  276. $('.cursorDrag').on('mouseleave', function () {
  277. self.$cursor1.classList.remove('drag', 'expand');
  278. });
  279. },
  280. cursorExplore: function () {
  281. var self = this;
  282. $('.cursorExplore').on('mouseenter', function () {
  283. self.$cursor1.classList.add('explore');
  284. });
  285. $('.cursorExplore').on('mouseleave', function () {
  286. self.$cursor1.classList.remove('explore');
  287. });
  288. },
  289. cursorZoom: function () {
  290. var self = this;
  291. $('.cursorZoom').on('mouseenter', function () {
  292. self.$cursor1.classList.add('zoom');
  293. });
  294. $('.cursorZoom').on('mouseleave', function () {
  295. self.$cursor1.classList.remove('zoom');
  296. });
  297. },
  298. cursorNext: function () {
  299. var self = this;
  300. $('.cursorNext').on('mouseenter', function () {
  301. self.$cursor1.classList.add('next');
  302. });
  303. $('.cursorNext').on('mouseleave', function () {
  304. self.$cursor1.classList.remove('next');
  305. });
  306. },
  307. cursorPrev: function () {
  308. var self = this;
  309. $('.cursorPrev').on('mouseenter', function () {
  310. self.$cursor1.classList.add('prev');
  311. });
  312. $('.cursorPrev').on('mouseleave', function () {
  313. self.$cursor1.classList.remove('prev');
  314. });
  315. }
  316. }
  317. if (!isMobile) {
  318. cursor.init(); //Init custom cursor
  319. }
  320. //--------------------------------------------------
  321. // Work detail slider
  322. //--------------------------------------------------
  323. workSlider();
  324. function workSlider() {
  325. var workSlide = $('.work-slider .owl-carousel');
  326. workSlide.owlCarousel({
  327. loop: true,
  328. margin: 30,
  329. mouseDrag: false,
  330. autoplay: false,
  331. center: false,
  332. dots: false,
  333. dragEndSpeed: 700,
  334. smartSpeed: 2000,
  335. responsiveClass: true,
  336. autoplayHoverPause: true,
  337. autoplayTimeout: 9000,
  338. responsive: {
  339. 0: {
  340. items: 1,
  341. margin: 0,
  342. },
  343. 600: {
  344. items: 1,
  345. margin: 0,
  346. },
  347. 1000: {
  348. items: 1,
  349. margin: 0,
  350. }
  351. }
  352. });
  353. $('.right-over-next').on("click", function () {
  354. workSlide.trigger('next.owl.carousel');
  355. })
  356. $('.right-over-prev').on("click", function () {
  357. workSlide.trigger('prev.owl.carousel');
  358. })
  359. }
  360. //--------------------------------------------------
  361. // Toggle Menu
  362. //--------------------------------------------------
  363. var t1 = new TimelineMax({
  364. paused: true
  365. });
  366. t1.to(".one", 0.4, {
  367. y: 9,
  368. autoAlpha: 0,
  369. ease: Expo.easeInOut
  370. });
  371. t1.to(".two", 0.4, {
  372. ease: Expo.easeInOut,
  373. delay: -1
  374. });
  375. t1.to(".tre", 0.4, {
  376. y: -9,
  377. autoAlpha: 0,
  378. ease: Expo.easeInOut,
  379. delay: -1
  380. });
  381. t1.to(".over-all", 0.5, {
  382. autoAlpha: 1,
  383. ease: Expo.easeOut,
  384. })
  385. t1.to(".bg-nav", 0.5, {
  386. autoAlpha: 1,
  387. ease: Power4.easeOut,
  388. delay: -1
  389. })
  390. t1.to(".menu", 0.5, {
  391. autoAlpha: 1,
  392. ease: Expo.easeOut,
  393. delay: -1
  394. })
  395. t1.staggerFrom(".menu ul li", 1.5, {
  396. y: 50,
  397. opacity: 0,
  398. ease: Power4.easeInOut,
  399. }, '0.1', '-0.01');
  400. t1.reverse();
  401. $('.toggle-btn').on("click", function () {
  402. t1.reversed(!t1.reversed()); //toggles the orientation
  403. })
  404. //--------------------------------------------------
  405. // Magnetic
  406. //--------------------------------------------------
  407. $(document).on('mousemove', function (e) {
  408. $('.magnetic').each(function () {
  409. if (!isMobile) {
  410. magnetic(this, e); //Init effect magnetic
  411. }
  412. });
  413. });
  414. function magnetic(el, e) {
  415. var mX = e.pageX,
  416. mY = e.pageY;
  417. const obj = $(el);
  418. const customDist = 20 * obj.data('dist') || 80,
  419. centerX = obj.offset().left + obj.width() / 2,
  420. centerY = obj.offset().top + obj.height() / 2;
  421. var deltaX = Math.floor((centerX - mX)) * -.4,
  422. deltaY = Math.floor((centerY - mY)) * -.4;
  423. var distance = calcDistance(obj, mX, mY);
  424. if (distance < customDist) {
  425. TweenMax.to(obj, .4, {
  426. y: deltaY,
  427. x: deltaX
  428. });
  429. } else {
  430. TweenMax.to(obj, .4, {
  431. y: 0,
  432. x: 0
  433. });
  434. }
  435. }
  436. function calcDistance(elem, mouseX, mouseY) {
  437. return Math.floor(Math.sqrt(Math.pow(mouseX - (elem.offset().left + (elem.width() / 2)), 2) + Math.pow(mouseY - (elem.offset().top + (elem.height() / 2)), 2)));
  438. }
  439. //--------------------------------------------------
  440. // Zoom Image
  441. //--------------------------------------------------
  442. mediumZoom(document.querySelectorAll('.cover'), {
  443. background: '#000',
  444. })
  445. var workSlide = new Swiper('.swiper-container', {
  446. slidesPerView: 1,
  447. pagination: {
  448. el: '.swiper-pagination',
  449. type: 'progressbar',
  450. },
  451. loop: false,
  452. centeredSlides: false,
  453. speed: 900,
  454. spaceBetween: 0,
  455. mousewheel: true,
  456. });
  457. workSlide.on('slideChange', function () {
  458. TweenMax.to('.text-1', 0.3, {
  459. y: '80',
  460. })
  461. TweenMax.to('.text-2', 0.3, {
  462. y: '80',
  463. })
  464. });
  465. workSlide.on('slideChangeTransitionEnd', function () {
  466. TweenMax.to('.text-1', 0.3, {
  467. y: '0',
  468. })
  469. TweenMax.to('.text-2', 0.3, {
  470. y: '0',
  471. })
  472. });
  473. var toggler = $('.menu__toggler');
  474. var menu = $('.menus');
  475. toggler.on("click", function () {
  476. toggler.toggleClass('activez');
  477. menu.toggleClass('activez');
  478. });
  479. })(jQuery);