飞天AI数字人展会页面
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

891 lines
29 KiB

6 months ago
  1. (function ($) {
  2. jQuery.fn.reverse = Array.prototype.reverse;
  3. var
  4. // auxiliar functions
  5. aux = {
  6. setup: function ($wrapper, $items, opts) {
  7. // set the wrappers position to relative
  8. $wrapper.css('position', 'relative');
  9. // save the items position
  10. aux.saveInitialPosition($items);
  11. // set the items to absolute and assign top & left
  12. $items.each(function (i) {
  13. var $item = $(this);
  14. $item.css({
  15. position: 'absolute',
  16. left: $item.data('left'),
  17. top: $item.data('top')
  18. });
  19. });
  20. // check how many items we have per row
  21. var rowCount = Math.floor($wrapper.width() / $items.width()),
  22. // number of items to show is rowCount * n rows
  23. shown = rowCount * opts.rows,
  24. // total number of rows
  25. totalRows = Math.ceil($items.length / rowCount);
  26. // save this values for later
  27. var config = {};
  28. config.currentRow = 1;
  29. config.totalRows = totalRows;
  30. config.rowCount = rowCount;
  31. config.shownItems = shown;
  32. $wrapper.data('config', config);
  33. // show n rowns
  34. $wrapper.children(':gt(' + (shown - 1) + ')').hide();
  35. // assign row classes to the items
  36. $items.each(function (i) {
  37. var $item = $(this),
  38. row = Math.ceil((i + 1) / rowCount);
  39. $item.addClass('tj_row_' + row);
  40. });
  41. nav.setup($wrapper, $items, opts);
  42. },
  43. saveInitialPosition: function ($items) {
  44. $items.each(function (i) {
  45. var $item = $(this);
  46. $item.data({
  47. left: $item.position().left + 'px',
  48. top: $item.position().top+ 'px'
  49. });
  50. });
  51. }
  52. },
  53. // navigation types
  54. nav = {
  55. setup: function ($wrapper, $items, opts) {
  56. nav[opts.type.mode].setup($wrapper, $items, opts);
  57. },
  58. def: {
  59. setup: function ($wrapper, $items, opts) {
  60. var config = $wrapper.data('config');
  61. $items.each(function (i) {
  62. var $item = $(this),
  63. row = Math.ceil((i + 1) / config.rowCount),
  64. t,
  65. f = row % opts.rows;
  66. if (f === 1) {
  67. t = '0px';
  68. } else if (f === 0) {
  69. t = (opts.rows - 1) * $items.height() + 'px';
  70. } else {
  71. t = (f - 1) * $items.height() + 'px';
  72. }
  73. $item.css({ top: t });
  74. });
  75. },
  76. pagination: function ($wrapper, dir, opts) {
  77. var config = $wrapper.data('config');
  78. if ((dir === 1 && config.currentRow + opts.rows > config.totalRows) ||
  79. (dir === -1 && config.currentRow - opts.rows <= 0)
  80. ) {
  81. $wrapper.data('anim', false);
  82. return false;
  83. }
  84. // var currentRows = '', nextRows = '';
  85. // for (var i = 0; i < opts.rows; ++i) {
  86. // currentRows += '.tj_row_' + (config.currentRow + i) + ',';
  87. // (dir === 1)
  88. // ? nextRows += '.tj_row_' + (config.currentRow + opts.rows + i) + ','
  89. // : nextRows += '.tj_row_' + (config.currentRow - 1 - i) + ',';
  90. // }
  91. // 使用数组来存储选择器
  92. var currentRows = [];
  93. var nextRows = [];
  94. // 获取当前行的起始位置
  95. var currentRowStart = config.currentRow;
  96. for (var i = 0; i < opts.rows; ++i) {
  97. // 生成当前行选择器并存储到数组中
  98. currentRows.push('.tj_row_' + (currentRowStart + i));
  99. // 根据方向计算下一行的选择器并存储到数组中
  100. if (dir === 1) {
  101. nextRows.push('.tj_row_' + (currentRowStart + opts.rows + i));
  102. } else {
  103. nextRows.push('.tj_row_' + (currentRowStart - 1 - i));
  104. }
  105. }
  106. // 通过 join(',') 将数组中的选择器连接成字符串
  107. currentRows = currentRows.join(',');
  108. nextRows = nextRows.join(',');
  109. $wrapper.children(currentRows).hide();
  110. $wrapper.children(nextRows).show();
  111. (dir === 1) ? config.currentRow += opts.rows : config.currentRow -= opts.rows;
  112. $wrapper.data('anim', false);
  113. $wrapper.data('config', config);
  114. }
  115. },
  116. fade: {
  117. setup: function ($wrapper, $items, opts) {
  118. // same like def mode
  119. nav['def'].setup($wrapper, $items, opts);
  120. },
  121. pagination: function ($wrapper, dir, opts) {
  122. var config = $wrapper.data('config');
  123. if ((dir === 1 && config.currentRow + opts.rows > config.totalRows) ||
  124. (dir === -1 && config.currentRow - opts.rows <= 0)
  125. ) {
  126. $wrapper.data('anim', false);
  127. return false;
  128. }
  129. // var currentRows = '', nextRows = '';
  130. // for (var i = 0; i < opts.rows; ++i) {
  131. // currentRows += '.tj_row_' + (config.currentRow + i) + ',';
  132. // (dir === 1)
  133. // ? nextRows += '.tj_row_' + (config.currentRow + opts.rows + i) + ','
  134. // : nextRows += '.tj_row_' + (config.currentRow - 1 - i) + ',';
  135. // }
  136. var currentRows = [];
  137. var nextRows = [];
  138. for (var i = 0; i < opts.rows; ++i) {
  139. currentRows.push('.tj_row_' + (config.currentRow + i));
  140. if (dir === 1) {
  141. nextRows.push('.tj_row_' + (config.currentRow + opts.rows + i));
  142. } else {
  143. nextRows.push('.tj_row_' + (config.currentRow - 1 - i));
  144. }
  145. }
  146. // 生成最终的选择器字符串
  147. currentRows = currentRows.join(',');
  148. nextRows = nextRows.join(',');
  149. $wrapper.children(currentRows).fadeOut(opts.type.speed, opts.type.easing);
  150. var $nextRowElements = $wrapper.children(nextRows),
  151. totalNextRows = $nextRowElements.length,
  152. cnt = 0;
  153. $nextRowElements.fadeIn(opts.type.speed, opts.type.easing, function () {
  154. ++cnt;
  155. if (cnt === totalNextRows) {
  156. $wrapper.data('anim', false);
  157. }
  158. });
  159. (dir === 1) ? config.currentRow += opts.rows : config.currentRow -= opts.rows;
  160. $wrapper.data('config', config);
  161. }
  162. },
  163. seqfade: {
  164. setup: function ($wrapper, $items, opts) {
  165. // same like def mode
  166. nav['def'].setup($wrapper, $items, opts);
  167. },
  168. pagination: function ($wrapper, dir, opts) {
  169. var config = $wrapper.data('config');
  170. if ((dir === 1 && config.currentRow + opts.rows > config.totalRows) ||
  171. (dir === -1 && config.currentRow - opts.rows <= 0)
  172. ) {
  173. $wrapper.data('anim', false);
  174. return false;
  175. }
  176. // var currentRows = '', nextRows = '';
  177. // for (var i = 0; i < opts.rows; ++i) {
  178. // currentRows += '.tj_row_' + (config.currentRow + i) + ',';
  179. // (dir === 1)
  180. // ? nextRows += '.tj_row_' + (config.currentRow + opts.rows + i) + ','
  181. // : nextRows += '.tj_row_' + (config.currentRow - 1 - i) + ',';
  182. // }
  183. // 使用数组来收集结果
  184. var currentRows = [];
  185. var nextRows = [];
  186. // 获取当前行和下一行的起始位置
  187. var currentStart = config.currentRow;
  188. var nextStartOffset = opts.rows;
  189. for (var i = 0; i < opts.rows; ++i) {
  190. // 将当前行的选择器加入数组
  191. currentRows.push('.tj_row_' + (currentStart + i));
  192. // 根据方向计算下一行的选择器并加入数组
  193. if (dir === 1) {
  194. nextRows.push('.tj_row_' + (currentStart + nextStartOffset + i));
  195. } else {
  196. nextRows.push('.tj_row_' + (currentStart - 1 - i));
  197. }
  198. }
  199. // 通过 join(',') 将数组中的选择器连接成字符串
  200. currentRows = currentRows.join(',');
  201. nextRows = nextRows.join(',');
  202. var seq_t = opts.type.factor;
  203. var $currentRowElements;
  204. (dir === 1)
  205. ? $currentRowElements = $wrapper.children(currentRows)
  206. : $currentRowElements = $wrapper.children(currentRows).reverse();
  207. $currentRowElements.each(function (i) {
  208. var $el = $(this);
  209. setTimeout(function () {
  210. $el.fadeOut(opts.type.speed, opts.type.easing)
  211. }, seq_t + i * seq_t);
  212. });
  213. var $nextRowElements;
  214. (dir === 1)
  215. ? $nextRowElements = $wrapper.children(nextRows)
  216. : $nextRowElements = $wrapper.children(nextRows).reverse();
  217. var total_elems = $nextRowElements.length,
  218. cnt = 0;
  219. $nextRowElements.each(function (i) {
  220. var $el = $(this);
  221. setTimeout(function () {
  222. $el.fadeIn(opts.type.speed, opts.type.easing, function () {
  223. ++cnt;
  224. if (cnt === total_elems) {
  225. $wrapper.data('anim', false);
  226. }
  227. })
  228. }, (seq_t * 2) + i * seq_t);
  229. });
  230. (dir === 1) ? config.currentRow += opts.rows : config.currentRow -= opts.rows;
  231. $wrapper.data('config', config);
  232. }
  233. },
  234. updown: {
  235. setup: function ($wrapper, $items, opts) {
  236. var config = $wrapper.data('config');
  237. $wrapper.children(':gt(' + (config.shownItems - 1) + ')').css('opacity', 0);
  238. $items.each(function (i) {
  239. var $item = $(this),
  240. row = Math.ceil((i + 1) / config.rowCount),
  241. t = $item.position().top,
  242. f = row % opts.rows;
  243. if (row > opts.rows) {
  244. t = (opts.rows * $items.height());
  245. }
  246. $item.css({ top: t + 'px' });
  247. });
  248. },
  249. pagination: function ($wrapper, dir, opts) {
  250. var config = $wrapper.data('config');
  251. if ((dir === 1 && config.currentRow + opts.rows > config.totalRows) ||
  252. (dir === -1 && config.currentRow - 1 <= 0)
  253. ) {
  254. $wrapper.data('anim', false);
  255. return false;
  256. }
  257. var movingRows = '';
  258. for (var i = 0; i <= opts.rows; ++i) {
  259. if (i > 0) movingRows += ','; // 添加逗号作为分隔符
  260. movingRows += '.tj_row_' + (dir === 1 ? (config.currentRow + i) : (config.currentRow + (i - 1)));
  261. }
  262. var $elements;
  263. (dir === 1)
  264. ? $elements = $wrapper.children(movingRows)
  265. : $elements = $wrapper.children(movingRows).reverse();
  266. var total_elems = $elements.length,
  267. cnt = 0;
  268. $elements.each(function (i) {
  269. var $el = $(this),
  270. row = $el.attr('class'),
  271. animParam = {},
  272. currentRow = config.currentRow;
  273. // if first row fade out
  274. // if last row fade in
  275. // for all the rows move them up / down
  276. if (dir === 1) {
  277. if (row === 'tj_row_' + (currentRow)) {
  278. animParam.opacity = 0;
  279. }
  280. else if (row === 'tj_row_' + (currentRow + opts.rows)) {
  281. animParam.opacity = 1;
  282. }
  283. }
  284. else {
  285. if (row === 'tj_row_' + (currentRow - 1)) {
  286. animParam.opacity = 1;
  287. }
  288. else if (row === 'tj_row_' + (currentRow + opts.rows - 1)) {
  289. animParam.opacity = 0;
  290. }
  291. }
  292. $el.show();
  293. (dir === 1)
  294. ? animParam.top = $el.position().top - $el.height() + 'px'
  295. : animParam.top = $el.position().top + $el.height() + 'px'
  296. $el.stop().animate(animParam, opts.type.speed, opts.type.easing, function () {
  297. if (parseInt(animParam.top) < 0 || parseInt(animParam.top) > $el.height() * (opts.rows - 1))
  298. $el.hide();
  299. ++cnt;
  300. if (cnt === total_elems) {
  301. $wrapper.data('anim', false);
  302. }
  303. });
  304. });
  305. (dir === 1) ? config.currentRow += 1 : config.currentRow -= 1;
  306. $wrapper.data('config', config);
  307. }
  308. },
  309. sequpdown: {
  310. setup: function ($wrapper, $items, opts) {
  311. // same like updown mode
  312. nav['updown'].setup($wrapper, $items, opts);
  313. },
  314. pagination: function ($wrapper, dir, opts) {
  315. var config = $wrapper.data('config');
  316. if ((dir === 1 && config.currentRow + opts.rows > config.totalRows) ||
  317. (dir === -1 && config.currentRow - 1 <= 0)
  318. ) {
  319. $wrapper.data('anim', false);
  320. return false;
  321. }
  322. var movingRows = '';
  323. for (var i = 0; i <= opts.rows; ++i) {
  324. if (i > 0) movingRows += ','; // 添加逗号作为分隔符
  325. movingRows += '.tj_row_' + (dir === 1 ? (config.currentRow + i) : (config.currentRow + (i - 1)));
  326. }
  327. var seq_t = opts.type.factor,
  328. $elements;
  329. var dircond = 1;
  330. if (opts.type.reverse) dircond = -1;
  331. (dir === dircond)
  332. ? $elements = $wrapper.children(movingRows)
  333. : $elements = $wrapper.children(movingRows).reverse();
  334. var total_elems = $elements.length,
  335. cnt = 0;
  336. $elements.each(function (i) {
  337. var $el = $(this),
  338. row = $el.attr('class'),
  339. animParam = {},
  340. currentRow = config.currentRow;
  341. setTimeout(function () {
  342. // if first row fade out
  343. // if last row fade in
  344. // for all the rows move them up / down
  345. if (dir === 1) {
  346. if (row === 'tj_row_' + (currentRow)) {
  347. animParam.opacity = 0;
  348. }
  349. else if (row === 'tj_row_' + (currentRow + opts.rows)) {
  350. animParam.opacity = 1;
  351. }
  352. }
  353. else {
  354. if (row === 'tj_row_' + (currentRow - 1)) {
  355. animParam.opacity = 1;
  356. }
  357. else if (row === 'tj_row_' + (currentRow + opts.rows - 1)) {
  358. animParam.opacity = 0;
  359. }
  360. }
  361. $el.show();
  362. (dir === 1)
  363. ? animParam.top = $el.position().top - $el.height() + 'px'
  364. : animParam.top = $el.position().top + $el.height() + 'px'
  365. $el.stop().animate(animParam, opts.type.speed, opts.type.easing, function () {
  366. if (parseInt(animParam.top) < 0 || parseInt(animParam.top) > $el.height() * (opts.rows - 1))
  367. $el.hide();
  368. ++cnt;
  369. if (cnt === total_elems) {
  370. $wrapper.data('anim', false);
  371. }
  372. });
  373. }, seq_t + i * seq_t);
  374. });
  375. (dir === 1) ? config.currentRow += 1 : config.currentRow -= 1;
  376. $wrapper.data('config', config);
  377. }
  378. },
  379. showhide: {
  380. setup: function ($wrapper, $items, opts) {
  381. var config = $wrapper.data('config');
  382. $items.each(function (i) {
  383. var $item = $(this),
  384. row = Math.ceil((i + 1) / config.rowCount),
  385. t,
  386. f = row % opts.rows;
  387. if (f === 1) {
  388. t = '0px';
  389. } else if (f === 0) {
  390. t = (opts.rows - 1) * $items.height() + 'px';
  391. } else {
  392. t = (f - 1) * $items.height() + 'px';
  393. }
  394. $item.css({ top: t });
  395. });
  396. },
  397. pagination: function ($wrapper, dir, opts) {
  398. var config = $wrapper.data('config');
  399. if ((dir === 1 && config.currentRow + opts.rows > config.totalRows) ||
  400. (dir === -1 && config.currentRow - opts.rows <= 0)
  401. ) {
  402. $wrapper.data('anim', false);
  403. return false;
  404. }
  405. // var currentRows = '', nextRows = '';
  406. // for (var i = 0; i < opts.rows; ++i) {
  407. // currentRows += '.tj_row_' + (config.currentRow + i) + ',';
  408. // (dir === 1)
  409. // ? nextRows += '.tj_row_' + (config.currentRow + opts.rows + i) + ','
  410. // : nextRows += '.tj_row_' + (config.currentRow - 1 - i) + ',';
  411. // }
  412. // 使用数组来存储选择器
  413. var currentRows = [];
  414. var nextRows = [];
  415. // 获取当前行的起始位置
  416. var currentRowStart = config.currentRow;
  417. for (var i = 0; i < opts.rows; ++i) {
  418. // 生成当前行选择器并存储到数组中
  419. currentRows.push('.tj_row_' + (currentRowStart + i));
  420. // 根据方向计算下一行的选择器并存储到数组中
  421. if (dir === 1) {
  422. nextRows.push('.tj_row_' + (currentRowStart + opts.rows + i));
  423. } else {
  424. nextRows.push('.tj_row_' + (currentRowStart - 1 - i));
  425. }
  426. }
  427. // 通过 join(',') 将数组中的选择器连接成字符串
  428. currentRows = currentRows.join(',');
  429. nextRows = nextRows.join(',');
  430. $wrapper.children(currentRows).hide(opts.type.speed, opts.type.easing);
  431. var $nextRowElements = $wrapper.children(nextRows),
  432. totalNextRows = $nextRowElements.length,
  433. cnt = 0;
  434. $nextRowElements.show(opts.type.speed, opts.type.easing, function () {
  435. ++cnt;
  436. if (cnt === totalNextRows) {
  437. $wrapper.data('anim', false);
  438. }
  439. });
  440. (dir === 1) ? config.currentRow += opts.rows : config.currentRow -= opts.rows;
  441. $wrapper.data('config', config);
  442. }
  443. },
  444. disperse: {
  445. setup: function ($wrapper, $items, opts) {
  446. var config = $wrapper.data('config');
  447. $items.each(function (i) {
  448. var $item = $(this),
  449. row = Math.ceil((i + 1) / config.rowCount),
  450. t,
  451. f = row % opts.rows;
  452. if (f === 1) {
  453. t = '0px';
  454. } else if (f === 0) {
  455. t = (opts.rows - 1) * $items.height() + 'px';
  456. } else {
  457. t = (f - 1) * $items.height() + 'px';
  458. }
  459. $item.css({ top: t }).data('top', t);
  460. });
  461. },
  462. pagination: function ($wrapper, dir, opts) {
  463. var config = $wrapper.data('config');
  464. if ((dir === 1 && config.currentRow + opts.rows > config.totalRows) ||
  465. (dir === -1 && config.currentRow - opts.rows <= 0)
  466. ) {
  467. $wrapper.data('anim', false);
  468. return false;
  469. }
  470. // var currentRows = '', nextRows = '';
  471. // for (var i = 0; i < opts.rows; ++i) {
  472. // currentRows += '.tj_row_' + (config.currentRow + i) + ',';
  473. // (dir === 1)
  474. // ? nextRows += '.tj_row_' + (config.currentRow + opts.rows + i) + ','
  475. // : nextRows += '.tj_row_' + (config.currentRow - 1 - i) + ',';
  476. // }
  477. // 使用数组来存储选择器
  478. var currentRows = [];
  479. var nextRows = [];
  480. // 获取当前行的起始位置
  481. var currentRowStart = config.currentRow;
  482. for (var i = 0; i < opts.rows; ++i) {
  483. // 生成当前行选择器并存储到数组中
  484. currentRows.push('.tj_row_' + (currentRowStart + i));
  485. // 根据方向计算下一行的选择器并存储到数组中
  486. if (dir === 1) {
  487. nextRows.push('.tj_row_' + (currentRowStart + opts.rows + i));
  488. } else {
  489. nextRows.push('.tj_row_' + (currentRowStart - 1 - i));
  490. }
  491. }
  492. // 通过 join(',') 将数组中的选择器连接成字符串
  493. currentRows = currentRows.join(',');
  494. nextRows = nextRows.join(',');
  495. $wrapper.children(currentRows).each(function (i) {
  496. var $el = $(this);
  497. $el.stop().animate({
  498. left: $el.position().left + Math.floor(Math.random() * 101) - 50 + 'px',
  499. top: $el.position().top + Math.floor(Math.random() * 101) - 50 + 'px',
  500. opacity: 0
  501. }, opts.type.speed, opts.type.easing, function () {
  502. $el.css({
  503. left: $el.data('left'),
  504. top: $el.data('top')
  505. }).hide();
  506. });
  507. });
  508. var $nextRowElements = $wrapper.children(nextRows);
  509. total_elems = $nextRowElements.length,
  510. cnt = 0;
  511. $nextRowElements.each(function (i) {
  512. var $el = $(this);
  513. $el.css({
  514. left: parseInt($el.data('left')) + Math.floor(Math.random() * 301) - 150 + 'px',
  515. top: parseInt($el.data('top')) + Math.floor(Math.random() * 301) - 150 + 'px',
  516. opacity: 0
  517. })
  518. .show()
  519. .animate({
  520. left: $el.data('left'),
  521. top: $el.data('top'),
  522. opacity: 1
  523. }, opts.type.speed, opts.type.easing, function () {
  524. ++cnt;
  525. if (cnt === total_elems) {
  526. $wrapper.data('anim', false);
  527. }
  528. });
  529. });
  530. (dir === 1) ? config.currentRow += opts.rows : config.currentRow -= opts.rows;
  531. $wrapper.data('config', config);
  532. }
  533. },
  534. rows: {
  535. setup: function ($wrapper, $items, opts) {
  536. // same like def mode
  537. nav['def'].setup($wrapper, $items, opts);
  538. },
  539. pagination: function ($wrapper, dir, opts) {
  540. var config = $wrapper.data('config');
  541. if ((dir === 1 && config.currentRow + opts.rows > config.totalRows) ||
  542. (dir === -1 && config.currentRow - opts.rows <= 0)
  543. ) {
  544. $wrapper.data('anim', false);
  545. return false;
  546. }
  547. // var currentRows = '', nextRows = '';
  548. // for (var i = 0; i < opts.rows; ++i) {
  549. // currentRows += '.tj_row_' + (config.currentRow + i) + ',';
  550. // (dir === 1)
  551. // ? nextRows += '.tj_row_' + (config.currentRow + opts.rows + i) + ','
  552. // : nextRows += '.tj_row_' + (config.currentRow - 1 - i) + ',';
  553. // }
  554. // 使用数组来存储选择器
  555. var currentRows = [];
  556. var nextRows = [];
  557. // 获取当前行的起始位置
  558. var currentRowStart = config.currentRow;
  559. for (var i = 0; i < opts.rows; ++i) {
  560. // 生成当前行选择器并存储到数组中
  561. currentRows.push('.tj_row_' + (currentRowStart + i));
  562. // 根据方向计算下一行的选择器并存储到数组中
  563. if (dir === 1) {
  564. nextRows.push('.tj_row_' + (currentRowStart + opts.rows + i));
  565. } else {
  566. nextRows.push('.tj_row_' + (currentRowStart - 1 - i));
  567. }
  568. }
  569. // 通过 join(',') 将数组中的选择器连接成字符串
  570. currentRows = currentRows.join(',');
  571. nextRows = nextRows.join(',');
  572. $wrapper.children(currentRows).each(function (i) {
  573. var $el = $(this),
  574. rownmb = $el.attr('class').match(/tj_row_(\d+)/)[1],
  575. diff;
  576. if (rownmb % 2 === 0) {
  577. diff = opts.type.factor;
  578. }
  579. else {
  580. diff = -opts.type.factor;
  581. }
  582. $el.stop().animate({
  583. left: $el.position().left + diff + 'px',
  584. opacity: 0
  585. }, opts.type.speed, opts.type.easing, function () {
  586. $el.css({
  587. left: $el.data('left')
  588. }).hide();
  589. });
  590. });
  591. var $nextRowElements = $wrapper.children(nextRows);
  592. total_elems = $nextRowElements.length,
  593. cnt = 0;
  594. $nextRowElements.each(function (i) {
  595. var $el = $(this),
  596. rownmb = $el.attr('class').match(/tj_row_(\d+)/)[1],
  597. diff;
  598. if (rownmb % 2 === 0) {
  599. diff = opts.type.factor;
  600. }
  601. else {
  602. diff = -opts.type.factor;
  603. }
  604. $el.css({
  605. left: parseInt($el.data('left')) + diff + 'px',
  606. opacity: 0
  607. })
  608. .show()
  609. .animate({
  610. left: $el.data('left'),
  611. opacity: 1
  612. }, opts.type.speed, opts.type.easing, function () {
  613. ++cnt;
  614. if (cnt === total_elems) {
  615. $wrapper.data('anim', false);
  616. }
  617. });
  618. });
  619. (dir === 1) ? config.currentRow += opts.rows : config.currentRow -= opts.rows;
  620. $wrapper.data('config', config);
  621. }
  622. }
  623. },
  624. methods = {
  625. init: function (options) {
  626. if (this.length) {
  627. var settings = {
  628. rows: 2,
  629. navL: '#tj_prev',
  630. navR: '#tj_next',
  631. type: {
  632. mode: 'def', // use def | fade | seqfade | updown | sequpdown | showhide | disperse | rows
  633. speed: 500, // for fade, seqfade, updown, sequpdown, showhide, disperse, rows
  634. easing: 'jswing', // for fade, seqfade, updown, sequpdown, showhide, disperse, rows
  635. factor: 50, // for seqfade, sequpdown, rows
  636. reverse: false // for sequpdown
  637. }
  638. };
  639. return this.each(function () {
  640. // if options exist, lets merge them with our default settings
  641. if (options) {
  642. $.extend(settings, options);
  643. }
  644. var $el = $(this).css('visibility', 'hidden'),
  645. // the ul
  646. $wrapper = $el.find('ul.tj_gallery'),
  647. // the items
  648. $thumbs = $wrapper.children('li'),
  649. total = $thumbs.length,
  650. // the navigation elements
  651. $p_nav = $(settings.navL),
  652. $n_nav = $(settings.navR);
  653. // save current row for later (first visible row)
  654. //config.currentRow = 1;
  655. // flag to control animation progress
  656. $wrapper.data('anim', false);
  657. // preload thumbs
  658. var loaded = 0;
  659. $thumbs.find('img').each(function (i) {
  660. var $img = $(this);
  661. $('<img/>').on('load', function () {
  662. ++loaded;
  663. if (loaded === total) {
  664. // setup
  665. aux.setup($wrapper, $thumbs, settings);
  666. $el.css('visibility', 'visible');
  667. // navigation events
  668. if ($p_nav.length) {
  669. $p_nav.on('click.gridnav', function (e) {
  670. if ($wrapper.data('anim')) return false;
  671. $wrapper.data('anim', true);
  672. nav[settings.type.mode].pagination($wrapper, -1, settings);
  673. return false;
  674. });
  675. }
  676. if ($n_nav.length) {
  677. $n_nav.on('click.gridnav', function (e) {
  678. if ($wrapper.data('anim')) return false;
  679. $wrapper.data('anim', true);
  680. nav[settings.type.mode].pagination($wrapper, 1, settings);
  681. return false;
  682. });
  683. }
  684. /*
  685. adds events to the mouse
  686. */
  687. // $el.on('mousewheel.gridnav', function (e, delta) {
  688. // if (delta > 0) {
  689. // if ($wrapper.data('anim')) return false;
  690. // $wrapper.data('anim', true);
  691. // nav[settings.type.mode].pagination($wrapper, -1, settings);
  692. // }
  693. // else {
  694. // if ($wrapper.data('anim')) return false;
  695. // $wrapper.data('anim', true);
  696. // nav[settings.type.mode].pagination($wrapper, 1, settings);
  697. // }
  698. // return false;
  699. // });
  700. $el.on('wheel.gridnav', function(e) {
  701. var delta = e.originalEvent.deltaY; // 使用 deltaY 来检测滚轮方向
  702. var direction = delta > 0 ? 1 : -1;
  703. if ($wrapper.data('anim')) {
  704. return false;
  705. }
  706. $wrapper.data('anim', true);
  707. nav[settings.type.mode].pagination($wrapper, direction, settings);
  708. return false;
  709. });
  710. }
  711. }).attr('src', $img.attr('src'));
  712. });
  713. });
  714. }
  715. }
  716. };
  717. $.fn.gridnav = function (method) {
  718. if (methods[method]) {
  719. return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
  720. } else if (typeof method === 'object' || !method) {
  721. return methods.init.apply(this, arguments);
  722. } else {
  723. $.error('Method ' + method + ' does not exist on jQuery.gridnav');
  724. }
  725. };
  726. })(jQuery);