productMK.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /**
  2. *
  3. * @authors Your Name (you@example.org)
  4. * @date 2017-07-14 10:48:36
  5. * @version $Id$
  6. */
  7. $(document).ready(function () {
  8. var checkBrowser = function () {
  9. var browserType = TD.util.browserType();
  10. console.log(browserType);
  11. if (browserType !== 'Chrome' && browserType !=='Safari') {
  12. console.log('not webkit');
  13. $('.effect-layer').hide();
  14. }
  15. }
  16. var checkSize = function () {
  17. var clientWidth = document.documentElement.clientWidth || document.body.clientWidth
  18. var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
  19. console.log(clientWidth, clientHeight);
  20. if (clientWidth / clientHeight < 16/9) {
  21. return 0;
  22. } else {
  23. return 1;
  24. }
  25. }
  26. var bgMode = checkSize();
  27. var langHandler = function () {
  28. if ($('.nav-lang-current').find('.nav-lang-item').text() === 'EN') {
  29. $('.scroll-text-title').each(function () {
  30. var newText = $(this).html().replace(/&nbsp;/g, ' ');
  31. newText = newText.replace(/<br>/g, ' ');
  32. $(this).html(newText);
  33. })
  34. $('.scroll-text-content').each(function () {
  35. var newText = $(this).html().replace(/&nbsp;/g, ' ');
  36. newText = newText.replace(/<br>/g, ' ');
  37. $(this).html(newText);
  38. })
  39. $('.scroll-text-subtitle').each(function () {
  40. var newText = $(this).html().replace(/&nbsp;/g, ' ');
  41. newText = newText.replace(/<br>/g, ' ');
  42. $(this).html(newText);
  43. })
  44. };
  45. }
  46. var initFullpage = function (ele) {
  47. $(ele).fullpage({
  48. // css3: true,
  49. easing: 'cubic-bezier(.62,.01,0,1)',
  50. easingcss3: 'cubic-bezier(.62,.01,0,1)',
  51. navigation: true,
  52. navigationPosition: 'right',
  53. scrollOverflow: true,
  54. afterRender: function () {
  55. // 首屏标题字体大小调整
  56. if ($('.nav-lang-current').find('.nav-lang-item').text() !== 'EN') {
  57. if ($('.scroll-text-subtitle').text().replace(/[\s\d]/g, '').length > 10) {
  58. if (document.documentElement.clientWidth <= 1080) {
  59. $('.scroll-text-subtitle').css('fontSize', '0.36rem');
  60. } else {
  61. $('.scroll-text-subtitle').css('fontSize', '0.72rem');
  62. }
  63. }
  64. }
  65. if (document.documentElement.clientWidth > 1080) {
  66. var scrollVideoEl = $('#scrollVideo');
  67. bgMode = checkSize();
  68. console.log(bgMode,'bgmode');
  69. if (bgMode) {
  70. scrollVideoEl.css('width', '100%');
  71. scrollVideoEl.css('height', 'auto');
  72. } else {
  73. scrollVideoEl.css('height', '100%');
  74. scrollVideoEl.css('width', 'auto');
  75. }
  76. }
  77. // 移动端去除换行
  78. // if (document.documentElement.clientWidth <= 1080) {
  79. // $('.scroll-text-content').each(function () {
  80. // $(this).html($(this).html().replace(/<br>/g, ''));
  81. // // 文字过少则居中
  82. // if ($(this).text().replace(/[\s\d]/g, '').length < 25) {
  83. // $(this).css('textAlign', 'center');
  84. // }
  85. // })
  86. // }
  87. $(window).resize();
  88. },
  89. onLeave: function (index, nextIndex, direction) {
  90. console.log(index, nextIndex, direction);
  91. var sectionNow = $(ele + '>:nth-child(' + index + ')').find('.scroll-inner');
  92. var sectionNext = $(ele + '>:nth-child(' + nextIndex + ')').find('.scroll-inner');
  93. if (bgMode) {
  94. sectionNow.hasClass('ani-bgscale-x') &&
  95. sectionNow.removeClass('ani-bgscale-x');
  96. sectionNext.hasClass('ani-bgscale-x') ||
  97. sectionNext.addClass('ani-bgscale-x');
  98. } else {
  99. sectionNow.hasClass('ani-bgscale-y') &&
  100. sectionNow.removeClass('ani-bgscale-y');
  101. sectionNext.hasClass('ani-bgscale-y') ||
  102. sectionNext.addClass('ani-bgscale-y');
  103. }
  104. if ($('.scroll-video').find('video').length === 0) return;
  105. if (nextIndex === 3) {
  106. $('.scroll-video').find('video')[0].play();
  107. }
  108. if (index === 3) {
  109. // $('.scroll-video').find('video')[0].currentTime = 0;
  110. $('.scroll-video').find('video')[0].pause();
  111. setTimeout(function () {
  112. $('.scroll-video').find('video')[0].currentTime = 0;
  113. }, 600);
  114. }
  115. }
  116. });
  117. }
  118. var innerPageHandler = function () {
  119. var outerWrapEl = $('.outer-wrap');
  120. var innerWrapEl = $('.inner-wrap');
  121. innerWrapEl.hide();
  122. $('.btn-inner').on('click', function () {
  123. $.fn.fullpage.destroy('all');
  124. outerWrapEl.hide();
  125. innerWrapEl.show();
  126. initFullpage('.inner-wrap');
  127. $.fn.fullpage.moveTo(1);
  128. })
  129. $('.btn-outer').on('click', function () {
  130. $.fn.fullpage.destroy('all');
  131. innerWrapEl.hide();
  132. outerWrapEl.show();
  133. initFullpage('.outer-wrap');
  134. setTimeout(function () {
  135. $(window).resize();
  136. }, 0)
  137. $.fn.fullpage.moveTo(1);
  138. })
  139. }
  140. var videoLayerHandler = function () {
  141. var videoShort = document.getElementById('scrollVideo');
  142. var videoObj = document.getElementById('videoObj');
  143. // $('.video-tv>img').on('click', function () {
  144. // if (videoObj.networkState !== 3) {
  145. // $('.video-layer').show();
  146. // videoObj.play();
  147. // } else {
  148. // console.log('视频不存在');
  149. // alert('视频不存在');
  150. // }
  151. // })
  152. $('.btn-videoplay').on('click', function () {
  153. console.log('videoplay');
  154. if (videoObj.networkState !== 3) {
  155. videoShort.pause();
  156. $.fn.fullpage.setAllowScrolling(false);
  157. $('.video-layer').show();
  158. videoObj.play();
  159. } else {
  160. console.log('视频不存在');
  161. alert('视频不存在');
  162. }
  163. })
  164. $('.video-layer').on('click', function (evt) {
  165. var evt = evt || window.event;
  166. var target = evt.target || evt.srcElement;
  167. if (target.nodeName.toLowerCase() === 'video') {
  168. if (videoObj.paused === true) {
  169. videoObj.play();
  170. } else {
  171. videoObj.pause();
  172. }
  173. } else {
  174. videoObj.pause();
  175. videoObj.currentTime = 0;
  176. $(this).hide();
  177. $.fn.fullpage.setAllowScrolling(true);
  178. videoShort.play();
  179. }
  180. })
  181. }
  182. var pageInit = function () {
  183. checkBrowser();
  184. langHandler();
  185. // 移动端移除视频部分
  186. if (document.documentElement.clientWidth <= 1080) {
  187. $('.scroll-video').remove();
  188. }
  189. // 判断背景图动画采用的bg-size形式
  190. $(window).on('resize', function () {
  191. bgMode = checkSize();
  192. })
  193. // 全屏滚动
  194. initFullpage('.outer-wrap');
  195. // 内胆页处理
  196. $('.inner-wrap').length && innerPageHandler();
  197. // 视频层处理
  198. $('.video-layer').length && videoLayerHandler();
  199. // 判断是否是缓存加载
  200. var isCache = false;
  201. var cacheCheck = function () {
  202. var imgTest = new Image();
  203. imgTest.src = $('.img-preload').children(0).attr('src');
  204. if (imgTest.complete === true) {
  205. isCache = true;
  206. }
  207. }
  208. cacheCheck();
  209. TD.imgPreload(function () {
  210. $('.m-loading').fadeOut(300);
  211. setTimeout(function () {
  212. $(window).resize();
  213. }, 0);
  214. })
  215. // 字体预加载处理
  216. var fontOver = false; // 字体是否处理完毕
  217. var fontLoader = function () {
  218. if ($('.nav-lang-current').find('.nav-lang-item').text() === '繁体') {
  219. // $('.scroll-text-title').css('font-family', '"LiSong Pro", "MingLiU", "Microsoft YaHei"');
  220. // $('.scroll-text-title').css('font-weight', '800');
  221. // $('.scroll-text-subtitle').css('font-family', '"LiSong Pro", "MingLiU", "Microsoft YaHei"');
  222. // $('.scroll-text-subtitle').css('font-weight', '800');
  223. return;
  224. };
  225. if ($('.nav-lang-current').find('.nav-lang-item').text() === 'EN') {
  226. return;
  227. }
  228. $('.scroll-text-title').css('fontFamily', "'newFont', 'PingFang SC', 'STHeiti', 'Microsoft YaHei'");
  229. $('.scroll-text-subtitle').css('fontFamily', "'newFont', 'PingFang SC', 'STHeiti', 'Microsoft YaHei'");
  230. $('.scroll-text-title').css('fontWeight', 400);
  231. $('.scroll-text-subtitle').css('fontWeight', 400);
  232. fontOver = true;
  233. }
  234. window.onload = function () {
  235. isCache = false;
  236. fontOver || fontLoader();
  237. }
  238. window.onpageshow = function (evt) {
  239. console.log(evt.persisted)
  240. evt.persisted && fontOver || fontLoader();
  241. }
  242. setTimeout(function () {
  243. if (isCache) {
  244. fontOver || fontLoader();
  245. }
  246. }, 100);
  247. }
  248. pageInit();
  249. });