list.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. var ease = {
  2. linear: function (e) {
  3. return e;
  4. },
  5. easeInQuad: function (e) {
  6. return e * e;
  7. },
  8. easeOutQuad: function (e) {
  9. return e * (2 - e);
  10. },
  11. easeInOutQuad: function (e) {
  12. return e < 0.5 ? 2 * e * e : (4 - 2 * e) * e - 1;
  13. },
  14. easeInCubic: function (e) {
  15. return e * e * e;
  16. },
  17. easeOutCubic: function (e) {
  18. return --e * e * e + 1;
  19. },
  20. easeInOutCubic: function (e) {
  21. return e < 0.5 ? 4 * e * e * e : (e - 1) * (2 * e - 2) * (2 * e - 2) + 1;
  22. },
  23. easeInQuart: function (e) {
  24. return e * e * e * e;
  25. },
  26. easeOutQuart: function (e) {
  27. return 1 - --e * e * e * e;
  28. },
  29. easeInOutQuart: function (e) {
  30. return e < 0.5 ? 8 * e * e * e * e : 1 - 8 * --e * e * e * e;
  31. },
  32. easeInQuint: function (e) {
  33. return e * e * e * e * e;
  34. },
  35. easeOutQuint: function (e) {
  36. return 1 + --e * e * e * e * e;
  37. },
  38. easeInOutQuint: function (e) {
  39. return e < 0.5 ? 16 * e * e * e * e * e : 1 + 16 * --e * e * e * e * e;
  40. },
  41. easeInOutCustom: function (e) {
  42. return e < 0.5 ? 16 * e * e * e * e * e : 1 + 16 * --e * e * e * e * e;
  43. },
  44. };
  45. var NEWTON_ITERATIONS = 4,
  46. NEWTON_MIN_SLOPE = 0.001,
  47. SUBDIVISION_PRECISION = 1e-7,
  48. SUBDIVISION_MAX_ITERATIONS = 10,
  49. kSplineTableSize = 11,
  50. kSampleStepSize = 1 / (kSplineTableSize - 1),
  51. float32ArraySupported = "function" == typeof Float32Array,
  52. easeInOut = new bezier(0.57, 0.09, 0.105, 1.005);
  53. function ads(e, t) {
  54. (document.getElementById(t) || document.documentElement).classList.add(e);
  55. }
  56. function rds(e, t) {
  57. (document.getElementById(t) || document.documentElement).classList.remove(e);
  58. }
  59. function event(e, t, r, n) {
  60. // ga && ga('send', 'event', e, t, r, n);
  61. }
  62. function Vec2(e, t) {
  63. this.x = e;
  64. this.y = t;
  65. this.lerp = function (e, t) {
  66. (this.x += (e.x - this.x) * t), (this.y += (e.y - this.y) * t);
  67. };
  68. this.plus = function (e) {
  69. return new Vec2(this.x + e.x, this.y + e.y);
  70. };
  71. this.minus = function (e) {
  72. return new Vec2(this.x - e.x, this.y - e.y);
  73. };
  74. this.length = function () {
  75. return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
  76. };
  77. }
  78. function A(e, t) {
  79. return 1 - 3 * t + 3 * e;
  80. }
  81. function B(e, t) {
  82. return 3 * t - 6 * e;
  83. }
  84. function C(e) {
  85. return 3 * e;
  86. }
  87. function calcBezier(e, t, r) {
  88. return ((A(t, r) * e + B(t, r)) * e + C(t)) * e;
  89. }
  90. function getSlope(e, t, r) {
  91. return 3 * A(t, r) * e * e + 2 * B(t, r) * e + C(t);
  92. }
  93. function binarySubdivide(e, t, r, n, o) {
  94. for (var i, a, l = 0; 0 < (i = calcBezier((a = t + (r - t) / 2), n, o) - e) ? (r = a) : (t = a), Math.abs(i) > SUBDIVISION_PRECISION && ++l < SUBDIVISION_MAX_ITERATIONS; );
  95. return a;
  96. }
  97. function newtonRaphsonIterate(e, t, r, n) {
  98. for (var o = 0; o < NEWTON_ITERATIONS; ++o) {
  99. var i = getSlope(t, r, n);
  100. if (0 === i) return t;
  101. t -= (calcBezier(t, r, n) - e) / i;
  102. }
  103. return t;
  104. }
  105. function LinearEasing(e) {
  106. return e;
  107. }
  108. function bezier(a, t, l, r) {
  109. if (!(0 <= a && a <= 1 && 0 <= l && l <= 1)) throw new Error("bezier x values must be in [0, 1] range");
  110. if (a === t && l === r) return LinearEasing;
  111. for (var s = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize), e = 0; e < kSplineTableSize; ++e) s[e] = calcBezier(e * kSampleStepSize, a, l);
  112. return function (e) {
  113. return 0 === e
  114. ? 0
  115. : 1 === e
  116. ? 1
  117. : calcBezier(
  118. (function (e) {
  119. for (var t = 0, r = 1, n = kSplineTableSize - 1; r !== n && s[r] <= e; ++r) t += kSampleStepSize;
  120. var o = t + ((e - s[--r]) / (s[r + 1] - s[r])) * kSampleStepSize,
  121. i = getSlope(o, a, l);
  122. return NEWTON_MIN_SLOPE <= i ? newtonRaphsonIterate(e, o, a, l) : 0 === i ? o : binarySubdivide(e, t, t + kSampleStepSize, a, l);
  123. })(e),
  124. t,
  125. r
  126. );
  127. };
  128. }
  129. var animUtil = {
  130. queue: [],
  131. i: 0,
  132. init: function () {
  133. browserController.addToRenderLoop(animUtil.render);
  134. },
  135. runAnimation: function (e, t, r, n) {
  136. var o = {
  137. callback: e,
  138. duration: t,
  139. easing: r,
  140. then: n,
  141. t: 0,
  142. p: 0,
  143. end: function () {
  144. animUtil.finish(this);
  145. },
  146. finished: !1,
  147. };
  148. return animUtil.queue.push(o), o;
  149. },
  150. render: function () {
  151. for (animUtil.i = 0; animUtil.i < animUtil.queue.length; animUtil.i++) animUtil.run(animUtil.queue[animUtil.i]);
  152. },
  153. run: function (e) {
  154. (e.t += browserController.state.delta), (e.p = Math.min(1, e.t / e.duration)), e.callback(e.easing ? e.easing(e.p) : e.p), 1 <= e.p && animUtil.finish(e);
  155. },
  156. finish: function (e) {
  157. e.then && e.then(), (e.finished = !0), animUtil.queue.splice(animUtil.queue.indexOf(e), 1), animUtil.i--;
  158. },
  159. };
  160. /**导航控制器 已整理完毕*/
  161. var navigationController = {
  162. startSite: function () {
  163. let ti = setTimeout(function () {
  164. clearTimeout(ti);
  165. ads("show-grid");
  166. // if (isFirstLoad) {
  167. // setTimeout(function () {
  168. // ads("show-intro");
  169. // }, 10);
  170. // }
  171. }, 400);
  172. },
  173. };
  174. /**浏览器控制器 已整理完毕*/
  175. var browserController = {
  176. state: {
  177. scrollTop: 0,
  178. toRender: [],
  179. toResize: [],
  180. resizeTimeout: null,
  181. mouse: {
  182. x: 0,
  183. y: 0,
  184. xLag: 0,
  185. yLag: 0,
  186. lag: 3,
  187. xLagSlow: 0,
  188. yLagSlow: 0,
  189. slowLag: 20,
  190. down: !1,
  191. },
  192. dpi: window.devicePixelRatio || 1,
  193. t: 0,
  194. d: Date.now(),
  195. delta: 0,
  196. rem: 0,
  197. isMobile: window.innerWidth < 800,
  198. isPortrait: window.innerHeight > window.innerWidth,
  199. },
  200. initialize: function () {
  201. window.addEventListener("resize", browserController.onResize);
  202. browserController.renderLoop();
  203. },
  204. addToRenderLoop: function (e) {
  205. browserController.state.toRender.push(e);
  206. browserController.state.toRender.push(() => {});
  207. },
  208. addToResizeLoop: function (e) {
  209. browserController.state.toResize.push(e);
  210. },
  211. renderBaseWork: function () {
  212. browserController.state.delta = Date.now() - browserController.state.d;
  213. browserController.state.t += browserController.state.delta;
  214. browserController.state.d = Date.now();
  215. browserController.state.mouse.xLag += (browserController.state.mouse.x - browserController.state.mouse.xLag) / browserController.state.mouse.lag;
  216. browserController.state.mouse.yLag += (browserController.state.mouse.y - browserController.state.mouse.yLag) / browserController.state.mouse.lag;
  217. browserController.state.mouse.xLagSlow += (browserController.state.mouse.x - browserController.state.mouse.xLagSlow) / browserController.state.mouse.slowLag;
  218. browserController.state.mouse.yLagSlow += (browserController.state.mouse.y - browserController.state.mouse.yLagSlow) / browserController.state.mouse.slowLag;
  219. },
  220. renderLoop: function () {
  221. browserController.renderBaseWork();
  222. browserController.state.toRender.forEach(function (e) {
  223. e();
  224. });
  225. requestAnimationFrame(browserController.renderLoop);
  226. },
  227. onResize: function () {
  228. clearTimeout(browserController.state.resizeTimeout), (browserController.state.resizeTimeout = setTimeout(browserController.resizeLoop, 100));
  229. },
  230. resizeLoop: function () {
  231. browserController.state.toResize.forEach(function (e) {
  232. e();
  233. });
  234. },
  235. };
  236. /**拖拽工具 已整理完毕*/
  237. var dragUtil = {
  238. state: {
  239. draggableElements: [],
  240. },
  241. init: function () {
  242. browserController.addToRenderLoop(dragUtil.render);
  243. window.addEventListener("mouseout", function (e) {
  244. var t = (e = e || window.event).relatedTarget || e.toElement;
  245. (t && "HTML" != t.nodeName) || dragUtil.endAllDrags();
  246. });
  247. },
  248. registerDraggableElement: function (e, t) {
  249. var r = {
  250. el: e,
  251. callback: t,
  252. dragging: !1,
  253. startPos: {
  254. x: 0,
  255. y: 0,
  256. },
  257. currentPos: {
  258. x: 0,
  259. y: 0,
  260. },
  261. diff: {
  262. x: 0,
  263. y: 0,
  264. },
  265. thisDiff: {
  266. x: 0,
  267. y: 0,
  268. },
  269. endDrag: function () {
  270. this.dragging = !1;
  271. },
  272. getDist: function () {
  273. return Math.sqrt(Math.pow(this.diff.x, 2) + Math.pow(this.diff.y, 2));
  274. },
  275. };
  276. e.addEventListener("mousedown", dragUtil.onDragStart.bind(dragUtil, r)),
  277. e.addEventListener("mousemove", dragUtil.onDragMove.bind(dragUtil, r)),
  278. e.addEventListener("mouseup", dragUtil.onDragEnd.bind(dragUtil, r)),
  279. // e.addEventListener('mouseover', dragUtil.onMouseOver.bind(dragUtil, r)),
  280. // e.addEventListener('mouseout', dragUtil.onMouseOut.bind(dragUtil, r)),
  281. e.addEventListener("touchstart", dragUtil.onDragStart.bind(dragUtil, r)),
  282. e.addEventListener("touchmove", dragUtil.onDragMove.bind(dragUtil, r)),
  283. e.addEventListener("touchend", dragUtil.onDragEnd.bind(dragUtil, r)),
  284. dragUtil.state.draggableElements.push(r);
  285. },
  286. normalizeEvent: function (e) {
  287. return e.touches && 0 < e.touches.length ? ((e.clientX = e.touches[0].clientX), (e.clientY = e.touches[0].clientY)) : e.clientX || ((e.clientX = 0), (e.clientY = 0)), e;
  288. },
  289. onDragStart: function (e, t) {
  290. e.dragging = !0;
  291. t = dragUtil.normalizeEvent(t);
  292. e.startPos.x = e.currentPos.x = t.clientX;
  293. e.startPos.y = e.currentPos.y = t.clientY;
  294. e.diff.x = 0;
  295. e.diff.y = 0;
  296. e.thisDiff.x = 0;
  297. e.thisDiff.y = 0;
  298. gridController.state.isHandleDrag = !1;
  299. },
  300. onDragMove: function (e, t) {
  301. if (e.dragging) {
  302. t = dragUtil.normalizeEvent(t);
  303. e.currentPos.x = t.clientX;
  304. e.currentPos.y = t.clientY;
  305. var r = e.currentPos.x - e.startPos.x;
  306. var n = e.currentPos.y - e.startPos.y;
  307. e.thisDiff.x = r - e.diff.x;
  308. e.thisDiff.y = n - e.diff.y;
  309. e.diff.x = r;
  310. e.diff.y = n;
  311. // gridController.state.isHandleDrag = !1;
  312. }
  313. },
  314. onMouseOver: function (e, t) {
  315. t = dragUtil.normalizeEvent(t);
  316. e.startPos.x = e.currentPos.x = t.clientX;
  317. e.startPos.y = e.currentPos.y = t.clientY;
  318. e.diff.x = 0;
  319. e.diff.y = 0;
  320. e.thisDiff.x = 0;
  321. e.thisDiff.y = 0;
  322. e.endDrag();
  323. e.callback(e);
  324. },
  325. onMouseOut: function (e, t) {},
  326. onDragEnd: function (e) {
  327. e.dragging && (e.endDrag(), e.callback(e), (gridController.state.isHandleDrag = !0));
  328. },
  329. endAllDrags: function () {
  330. dragUtil.state.draggableElements.forEach(function (e) {
  331. dragUtil.onDragEnd(e);
  332. });
  333. },
  334. clearDraggableElements: function () {
  335. dragUtil.state.draggableElements = [];
  336. },
  337. render: function () {
  338. dragUtil.state.draggableElements.forEach(function (e) {
  339. e.dragging && e.callback(e);
  340. });
  341. },
  342. };
  343. /**网格控制器 */
  344. var gridController = {
  345. state: {
  346. items: [], //所有框
  347. showItems: {}, //在屏幕内的框
  348. imageAspect: Math.sqrt(3) / 2, //图像纵横比 原始0.65
  349. screenAspect: window.innerWidth / window.innerHeight, //屏幕纵横比
  350. gridEl: null,
  351. rows: 0,
  352. cols: 0,
  353. colWidth: 0,
  354. rowHeight: 0,
  355. itemSpace: 0, //间距
  356. itemWidth: 217 * (!window.isMobile ? 1 : 0.6),
  357. itemHeight: 251 * (!window.isMobile ? 1 : 0.6),
  358. flipWidth: 0,
  359. flipHeight: 0,
  360. target: new Vec2(1e8, 1e8),
  361. offset: new Vec2(1e8, 1e8),
  362. initTarget: new Vec2(1e8, 1e8),
  363. focus: null,
  364. selected: null,
  365. count: 32,
  366. lerpRate: 1,
  367. canDrag: !0,
  368. template: null,
  369. flipped: !1,
  370. canIncrement: !0,
  371. cardArray: null,
  372. needsCreate: !1,
  373. canSelect: 1,
  374. isHandleDrag: !0,
  375. isClick: false,
  376. },
  377. /**初始 */
  378. init: function (e) {
  379. gridController.state.grid = document.getElementById("grid");
  380. dragUtil.registerDraggableElement(gridController.state.grid, gridController.handleDrag);
  381. gridController.state.screenCenter = new Vec2(window.innerWidth / 2, window.innerHeight / 2);
  382. gridController.state.cardArray = e;
  383. gridController.create();
  384. browserController.addToRenderLoop(this.render);
  385. browserController.addToResizeLoop(this.handleResize);
  386. gridController.getgif(5);
  387. },
  388. //部分图片转为gif图
  389. getgif: function (seconds) {
  390. const tt = setTimeout(() => {
  391. clearTimeout(tt);
  392. $(".grid__itemPicture.hasurl").each(function () {
  393. const gif = $(this).attr("gif");
  394. const newSrc = `https://vr.njmuseum.com/img/ww/${gif}`;
  395. $(this).find("img").attr("src", newSrc);
  396. });
  397. }, seconds * 1000);
  398. },
  399. /**场景调整大小 */
  400. handleResize: function () {
  401. gridController.state.screenCenter = new Vec2(window.innerWidth / 2, window.innerHeight / 2);
  402. gridController.create();
  403. },
  404. /**创建网格 */
  405. create: function (boo = true) {
  406. var e = gridController.state.cardArray;
  407. //横屏/竖屏
  408. if (window.innerWidth > window.innerHeight) {
  409. let b = Math.ceil(window.innerHeight / (gridController.state.itemHeight * 0.75));
  410. n = Math.ceil(window.innerWidth / gridController.state.itemWidth) + 1;
  411. let c = Math.ceil(e.length / n);
  412. o = c > b ? c : b;
  413. o = o % 2 == 0 ? o : o + 1;
  414. } else {
  415. let a = Math.ceil(window.innerWidth / gridController.state.itemWidth) + 1;
  416. o = Math.ceil(window.innerHeight / (gridController.state.itemHeight * 0.75));
  417. o = o % 2 == 0 ? o : o + 1;
  418. let c = Math.ceil(e.length / o);
  419. n = c > a ? c : a;
  420. }
  421. gridController.state.rows = o;
  422. gridController.state.cols = n;
  423. gridController.state.colWidth = gridController.state.itemWidth;
  424. gridController.state.rowHeight = gridController.state.itemHeight;
  425. gridController.state.flipWidth = gridController.state.colWidth * n;
  426. gridController.state.flipHeight = gridController.state.rowHeight * o * 0.75;
  427. gridController.state.count = o * n;
  428. gridController.state.grid.innerHTML = "";
  429. gridController.state.showItems = {};
  430. gridController.state.items = [];
  431. gridController.state.target = new Vec2(1e8, 1e8);
  432. gridController.state.offset = new Vec2(1e8, 1e8);
  433. // debugger;
  434. for (var l = 0, s = 0; s < n; s++) {
  435. for (var d = 0; d < o; d++) {
  436. this.createItem(d, s, l);
  437. l++;
  438. }
  439. }
  440. let keys = Object.keys(gridController.state.showItems);
  441. if (keys.length >= e.length) {
  442. gridController.state.canDrag = 0;
  443. let showArr = [];
  444. if (e.length < 10) {
  445. // 排序逻辑
  446. const sortedArray = Object.values(gridController.state.showItems).sort((a, b) => a.interval - b.interval || b.intervalX - a.intervalX);
  447. // const sortedArray = [
  448. // ...Object.values(gridController.state.showItems),
  449. // ].sort(
  450. // (a, b) => a.intervalY - b.intervalY || a.intervalX - b.intervalX
  451. // );
  452. showArr = new Array(keys.length).fill(0);
  453. for (let i = 0; i < e.length; i++) {
  454. let obj = sortedArray[i];
  455. let inx = keys.indexOf(obj.index + "");
  456. showArr[inx] = e[i];
  457. }
  458. } else {
  459. let arr1 = new Array(keys.length).fill(0);
  460. showArr = gridController.replaceRandomly(arr1, e);
  461. }
  462. let nint = 0;
  463. gridController.state.items.forEach((n, inx) => {
  464. gridController.state.grid.append(n.el);
  465. if (keys.indexOf(n.index + "") != -1) {
  466. if (showArr[nint] != 0) {
  467. n.card.className = "grid__itemCard";
  468. n.el.id = showArr[nint] + "_" + n.index;
  469. n.el.style.zIndex = Math.floor(Math.random() * 9999);
  470. n.image = gridController.createImage(showArr[nint], "grid__itemPicture");
  471. n.card.append(n.image);
  472. }
  473. nint++;
  474. }
  475. });
  476. } else {
  477. let arr1 = new Array(gridController.state.items.length).fill(0);
  478. let showArr = gridController.replaceRandomly(arr1, e);
  479. gridController.state.items.forEach((n, inx) => {
  480. gridController.state.grid.append(n.el);
  481. let ids = showArr[inx] != 0 ? showArr[inx] : e[Math.floor(Math.random() * e.length)];
  482. n.card.className = "grid__itemCard";
  483. n.el.id = ids + "_" + n.index;
  484. n.el.style.zIndex = Math.floor(Math.random() * 9999);
  485. n.image = gridController.createImage(ids, "grid__itemPicture");
  486. n.card.append(n.image);
  487. });
  488. }
  489. },
  490. replaceRandomly: function (arr1, arr2) {
  491. const result = [...arr1];
  492. const availableIndices = result.map((_, index) => index);
  493. for (const value of arr2) {
  494. if (availableIndices.length === 0) break;
  495. const randomIndex = Math.floor(Math.random() * availableIndices.length);
  496. const targetIndex = availableIndices[randomIndex];
  497. result[targetIndex] = value;
  498. availableIndices.splice(randomIndex, 1);
  499. }
  500. return result;
  501. },
  502. /**创建网格单独对象 */
  503. createItem: function (e, t, r) {
  504. var n = {
  505. row: e,
  506. col: t,
  507. el: document.createElement("div"),
  508. offset: new Vec2(0, 0),
  509. pos: new Vec2(0, 0),
  510. target: new Vec2(0, 0),
  511. interval: 0,
  512. intervalX: 0,
  513. intervalY: 0,
  514. zDistance: 0,
  515. zTarget: 0,
  516. zRate: 0.1,
  517. angle: 0,
  518. angleTarget: 0,
  519. index: r,
  520. order: 0,
  521. uid: "",
  522. card: document.createElement("div"),
  523. back: document.createElement("div"),
  524. image: "",
  525. close: document.createElement("div"),
  526. anim: null,
  527. };
  528. n.el.className = "grid__item";
  529. n.el.id = n.index;
  530. n.card.className = "grid__itemCard showBack";
  531. n.back.className = "grid__itemBack";
  532. n.card.append(n.back);
  533. n.el.append(n.card);
  534. n.el.style.height = gridController.state.itemHeight + "px";
  535. n.el.style.width = gridController.state.itemWidth + "px";
  536. n.el.addEventListener("mousedown", gridController.setFocus.bind(n));
  537. n.el.addEventListener("touchstart", gridController.setFocus.bind(n));
  538. n.offset.x = t * (gridController.state.itemWidth + gridController.state.itemSpace) + (parseInt(e % 2) == 0 ? 0 : gridController.state.itemWidth / 2);
  539. n.offset.y = e * gridController.state.itemHeight * 0.75;
  540. let xx = ((n.offset.x + gridController.state.offset.x) % gridController.state.flipWidth) - gridController.state.colWidth;
  541. let yy = ((n.offset.y + gridController.state.offset.y) % gridController.state.flipHeight) - gridController.state.rowHeight;
  542. gridController.state.items.push(n);
  543. if (!window.isMobile) {
  544. if (xx >= gridController.state.itemWidth * 0.5 && xx < window.innerWidth - gridController.state.itemWidth * 1.5 && yy > 0 && yy < window.innerHeight - gridController.state.itemHeight * 0.75) {
  545. n.intervalX = Math.abs(xx + gridController.state.itemWidth * 0.5 - window.innerWidth * 0.5);
  546. n.intervalY = Math.abs(yy + gridController.state.itemHeight * 0.5 - window.innerHeight * 0.5);
  547. n.interval = gridController.calculateDistance(xx + gridController.state.itemWidth * 0.5, yy + gridController.state.itemHeight * 0.5);
  548. gridController.state.showItems[n.index] = n;
  549. }
  550. } else {
  551. // let w = $('.logo').width();
  552. // let h = $('.logo').height();
  553. // let ww = $('.select .option').width();
  554. // let hh = $('.select .option').height();
  555. // console.log(w, h, ww, hh, xx, yy, n.index);
  556. // console.log(gridController.state.target);
  557. //手机版
  558. if (
  559. // !(xx >= 0 && xx <= w && yy >= 0 && yy <= h) &&
  560. // !(xx >= ww && xx <= window.innerWidth && yy >= hh && yy <= h) &&
  561. xx >= 0 &&
  562. xx < window.innerWidth - gridController.state.itemWidth * 0.5 &&
  563. yy >= -10 &&
  564. yy < window.innerHeight - gridController.state.itemHeight * 0.75
  565. ) {
  566. n.intervalX = Math.abs(xx + gridController.state.itemWidth * 0.5 - window.innerWidth * 0.5);
  567. n.intervalY = Math.abs(yy + gridController.state.itemHeight * 0.5 - window.innerHeight * 0.5);
  568. n.interval = gridController.calculateDistance(xx + gridController.state.itemWidth * 0.5, yy + gridController.state.itemHeight * 0.75);
  569. gridController.state.showItems[n.index] = n;
  570. }
  571. }
  572. },
  573. /**计算网格到页面中心点的距离 */
  574. calculateDistance: function (pointX, pointY) {
  575. const dx = pointX - window.innerWidth * 0.5;
  576. const dy = pointY - window.innerHeight * 0.5;
  577. return Math.floor(Math.sqrt(dx * dx + dy * dy) * 100) / 100;
  578. },
  579. deleteItem: function (newArr) {
  580. gridController.state.items.forEach((e, t) => {
  581. gridController.state.grid.removeChild(e.el);
  582. });
  583. gridController.state.items = [];
  584. gridController.state.cardArray = newArr;
  585. gridController.create(false);
  586. gridController.positionCardsInCenter();
  587. var temptime = setTimeout(() => {
  588. gridController.deselectItem();
  589. clearTimeout(temptime);
  590. }, 100);
  591. },
  592. /**创建网格单独对象图 */
  593. createImage: function (e, t) {
  594. let gifArr = [
  595. // "hbts04",
  596. "10:12156",
  597. "0:5268",
  598. // '2:6587',
  599. // '0:8178',
  600. // '2:823',
  601. // '2:6923',
  602. "10:23225",
  603. "10:8069",
  604. "10:2259",
  605. "3:2106",
  606. "10:26104",
  607. "10:19001",
  608. "3:7550",
  609. "111111",
  610. "10:28529",
  611. ];
  612. var html = `<div class="${t} ${!lxs[e].url && gifArr.indexOf(e) != -1 ? "hasurl" : ""}" gif="${gifArr.indexOf(e) != -1 ? e + ".gif" : ""}">
  613. <img src="${`https://houseoss.4dkankan.com/project/hubeiMuseum/wwq/modelImg/${e}.png`}" />
  614. <div class="shadow">
  615. <div class="name">
  616. <i>${getName(lxs[e].name).dynasty}</i>
  617. <h3>${getName(lxs[e].name).name}</h3>
  618. </div>
  619. <div class="iconbox">
  620. <div class="threed" ></div>
  621. </div>
  622. <div class="coverbox">
  623. <div class="right" onclick="openDetail('${e}',event)"></div>
  624. </div>
  625. </div>
  626. </div>`;
  627. // 创建一个临时容器
  628. var container = document.createElement("div");
  629. container.innerHTML = html;
  630. // 返回生成的 DOM 元素
  631. return container.firstElementChild;
  632. },
  633. //拖拽
  634. handleDrag: function (e) {
  635. if (gridController.state.canDrag) {
  636. var t = browserController.state.isMobile ? 2 : 1;
  637. gridController.state.target.x += e.thisDiff.x * t;
  638. gridController.state.target.y += e.thisDiff.y * t;
  639. }
  640. 0 == e.dragging &&
  641. (e.getDist() < 10 && gridController.state.focus && (!gridController.state.selected && gridController.state.canSelect ? gridController.selectItem(gridController.state.focus) : gridController.deselectItem(), (gridController.state.canSelect = !0)), (gridController.state.focus = null));
  642. },
  643. //设置焦点
  644. setFocus: function () {
  645. gridController.state.focus = this;
  646. },
  647. // 选择某一个进详情页
  648. selectItem: function (e) {
  649. if ($("body").hasClass("wapbody") && !gridController.state.isClick && !$(e.el).hasClass("active")) {
  650. gridController.state.isClick = true;
  651. $(".grid__item").removeClass("active later");
  652. $(e.el).addClass("active");
  653. let ti = setTimeout(function () {
  654. clearTimeout(ti);
  655. $(e.el).addClass("later");
  656. gridController.state.isClick = false;
  657. }, 400);
  658. }
  659. },
  660. moveToCenterAnim: function (e) {
  661. this.item.target.x = this.item.pos.x = this.start.x + this.move.x * e;
  662. this.item.target.y = this.item.pos.y = this.start.y + this.move.y * e;
  663. },
  664. /**卡片中心位置 */
  665. positionCardsInCenter: function () {
  666. gridController.state.items.forEach(function (e, t) {
  667. var r = e.el.getBoundingClientRect(),
  668. n = new Vec2(gridController.state.screenCenter.x - r.width / 2, gridController.state.screenCenter.y - r.height / 2);
  669. e.target.x = e.pos.x = n.x;
  670. e.target.y = e.pos.y = n.y;
  671. gridController.drawItem(e);
  672. });
  673. },
  674. // 关闭详情页
  675. deselectItem: function () {
  676. gridController.state.selected = null;
  677. gridController.state.lerpRate = 0.19;
  678. setTimeout(function () {
  679. let keys = Object.keys(gridController.state.showItems);
  680. gridController.state.canDrag = gridController.state.cardArray.length > keys.length;
  681. gridController.state.lerpRate = 1;
  682. isSwitchingOver = true;
  683. }, 500);
  684. gridController.state.needsCreate && (gridController.create(), (gridController.state.needsCreate = !1));
  685. },
  686. setOrder: function (e) {
  687. e.order = gridController.getOrder(e);
  688. },
  689. getOrder: function (e) {
  690. return gridController.state.count - ((e.index - gridController.state.selected.index + gridController.state.count) % gridController.state.count);
  691. },
  692. render: function () {
  693. if (gridController.state.canDrag && gridController.state.isHandleDrag && !document.documentElement.classList.contains("show-intro") && $(".fp-completely").index() === 1) {
  694. // 文物自动移动
  695. gridController.state.target.x += 0.3;
  696. }
  697. gridController.state.offset.lerp(gridController.state.target, 0.1);
  698. gridController.state.items.forEach(gridController.updateItem);
  699. gridController.state.items.forEach(gridController.drawItem);
  700. },
  701. updateItem: function (e) {
  702. var t = gridController.state.selected == e;
  703. if (gridController.state.selected) {
  704. var r = gridController.state.flipped ? 10 : 6;
  705. e.zTarget = 2 * e.order - gridController.state.count + (t ? r : 0);
  706. } else {
  707. e.target.x = ((e.offset.x + gridController.state.offset.x) % gridController.state.flipWidth) - gridController.state.colWidth;
  708. e.target.y = ((e.offset.y + gridController.state.offset.y) % gridController.state.flipHeight) - gridController.state.rowHeight;
  709. }
  710. e.pos.lerp(e.target, gridController.state.lerpRate);
  711. },
  712. /**坐标更新 */
  713. drawItem: function (e) {
  714. var t;
  715. if (browserController.state.isMobile) {
  716. t = window.innerWidth / 40;
  717. } else {
  718. t = 1.5 * Math.min(12, Math.max(0, window.innerHeight - 550) / 40 + 4);
  719. }
  720. e.el.style.transform = "translate3d(" + e.pos.x + "px, " + e.pos.y + "px, " + e.zDistance * t + "px)";
  721. },
  722. updateInit: function (newArr) {
  723. if (isSwitchingOver) {
  724. isSwitchingOver = false;
  725. let allNum = 0;
  726. gridController.state.selected = gridController.state.items[0];
  727. gridController.state.items.forEach((e, t) => {
  728. var r = new Vec2(e.pos.x, e.pos.y),
  729. n = e.el.getBoundingClientRect(),
  730. o = new Vec2(n.left + n.width / 2, n.top + n.height / 2),
  731. i = gridController.state.screenCenter.minus(o);
  732. e.centerPos = gridController.state.screenCenter.minus(new Vec2(n.width / 2, n.height / 2));
  733. gridController.setOrder(e);
  734. gridController.state.lerpRate = 1;
  735. var a = e.index * 10 + Math.ceil(300 * Math.random()) + 100;
  736. setTimeout(() => {
  737. animUtil.runAnimation(
  738. gridController.moveToCenterAnim.bind({
  739. start: r,
  740. item: e,
  741. move: i,
  742. }),
  743. 600,
  744. easeInOut,
  745. () => {
  746. allNum++;
  747. if (allNum >= gridController.state.items.length) {
  748. gridController.deleteItem(newArr);
  749. gridController.state.target = new Vec2(1e8, 1e8);
  750. gridController.state.offset = new Vec2(1e8, 1e8);
  751. }
  752. }
  753. );
  754. }, 0);
  755. });
  756. gridController.getgif(3);
  757. }
  758. },
  759. };
  760. function gridinit() {
  761. browserController.initialize();
  762. animUtil.init();
  763. dragUtil.init();
  764. }