index.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. $(function() {
  2. modal.init();
  3. page.init();
  4. })
  5. function getQueryVariable(variable) {
  6. var query = window.location.search.substring(1);
  7. var vars = query.split("&");
  8. for (var i = 0; i < vars.length; i++) {
  9. var pair = vars[i].split("=");
  10. if (pair[0] == variable) { return pair[1]; }
  11. }
  12. return (false);
  13. }
  14. // 是否pc
  15. function IsPc() {
  16. if (!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)) {
  17. // pc
  18. return true
  19. }
  20. return false
  21. }
  22. // 是否微信
  23. function isWeChat() {
  24. if (typeof WeixinJSBridge !== "undefined") {
  25. return 1;
  26. }
  27. return 0;
  28. }
  29. // 是否ios
  30. function isiOS() {
  31. var isPc = IsPc();
  32. if (!isPc) {
  33. var u = navigator.userAgent;
  34. // var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
  35. var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  36. return isiOS
  37. }
  38. }
  39. // 联系qq客服
  40. function onQQService() {
  41. var jhKfQQ = 3563681140;
  42. if (isWeChat()) {
  43. alert("请在浏览器打开页面")
  44. return;
  45. }
  46. var isPc = IsPc();
  47. var urlMobil = `mqqwpa://im/chat?chat_type=wpa&uin=${jhKfQQ}&version=1&src_type=web&web_src=http:://wpa.b.qq.com`;
  48. var urlPc = `http://wpa.qq.com/msgrd?v=3&uin=${jhKfQQ}&site=qq&menu=yes`;
  49. var url = isPc ? urlPc : urlMobil;
  50. window.open(url, "_brank");
  51. }
  52. if (getQueryVariable('id')) {
  53. $('.header-elements').removeClass('hid');
  54. }
  55. var page = {
  56. appointCodeBase64: '',
  57. appointTeamCodeBase64: '',
  58. tipModalDes: [
  59. '为了更好的体验<br>请前往移动端参与活动',
  60. '扫一扫下载《问道》手游<br>完成预创角 领取预创角礼包'
  61. ],
  62. init: function() {
  63. // 卖点图
  64. if ($('.main-swiper .swiper-slide').length > 0) {
  65. var mainSwiper = new Swiper('.main-swiper', {
  66. loop: true,
  67. autoplay: {
  68. disableOnInteraction: false
  69. },
  70. effect: 'coverflow',
  71. centeredSlides: true,
  72. slidesPerView: 'auto',
  73. followFinger: true,
  74. slideToClickedSlide: true,
  75. coverflowEffect: {
  76. rotate: 0,
  77. stretch: 0,
  78. depth: 140,
  79. modifier: 2,
  80. slideShadows: true
  81. },
  82. navigation: {
  83. nextEl: '.swiper-button-next',
  84. prevEl: '.swiper-button-prev'
  85. }
  86. });
  87. }
  88. // 弹窗
  89. $(".btn-code-modal[data-type]").on('click', function() {
  90. var tip = parseInt($(this).attr('data-tip'));
  91. if (tip == 1) {
  92. modal.open('.tip-modal');
  93. }
  94. if (tip == 0) {
  95. modal.open('.download-modal');
  96. }
  97. // ios ios 敬请期待
  98. if (tip == 2) {
  99. modal.open('.ios-tips-modal');
  100. }
  101. });
  102. // 联系客服 qq
  103. $(".qq-icon").on("click", function() {
  104. onQQService()
  105. })
  106. // android 下载
  107. $('.ico-btn-android').on("click", function() {
  108. if (isiOS()) {
  109. $('.ico-btn-ios').click()
  110. return
  111. }
  112. window.open('https://game.jhfly.cn/download/wcfml_20210823_mid.apk')
  113. })
  114. }
  115. }
  116. /*模态框相关*/
  117. var modal = {
  118. preModal: '', // 当前\上一个开启的模态框的类名
  119. scrollWidth: '', // 浏览器滚动条宽度
  120. scrollTop: 0, // 开启模态框时页面滚动距离
  121. needCloseModal: '', // 需要关闭的模态框类名
  122. closeIng: false, // 是否正在关闭模态框
  123. delayTime: 300, // 模态框关闭所需时间
  124. preVideo: '', // 保存'video-data'中需要自动播放的video的Id
  125. focusEl: '', // 开启模态框前获取到焦点的元素
  126. opening: false, // 当前是否有开启的模态框
  127. scrollThrough: false, // 是否阻止滚动穿透
  128. open: function(className) {
  129. var that = this;
  130. // 若当前有开启的模态框,则关闭当前模态框后再开启需要开启的模态框
  131. if (that.opening) {
  132. that.hide(that.preModal);
  133. setTimeout(function() {
  134. that.open(className);
  135. }, that.delayTime);
  136. return;
  137. }
  138. that.opening = true;
  139. var openDalyTime = 0;
  140. if (that.closeIng) {
  141. openDalyTime = that.delayTime;
  142. }
  143. setTimeout(function() {
  144. that.preModal = className;
  145. that.focusEl = document.activeElement;
  146. that.scrollWidth = window.innerWidth - document.body.clientWidth;
  147. that.scrollTop = parseInt(that.getScrollTop());
  148. $('body').css('padding-right', that.scrollWidth + 'px');
  149. if (that.scrollThrough) {
  150. document.body.style.top = -that.scrollTop + 'px';
  151. $('body').addClass('modal-open');
  152. } else {
  153. $('body').addClass('modal-open-scroll-through');
  154. }
  155. $(that.preModal).css('display', 'flex').addClass('modal-active');
  156. $(that.needCloseModal).removeClass('modal-hide');
  157. /* 开启模态框后为当前模态框的关闭按钮获取焦点 */
  158. $(className + " [data='close']").focus();
  159. }, openDalyTime)
  160. },
  161. hide: function(className) {
  162. var that = this;
  163. that.needCloseModal = className;
  164. that.closeIng = true;
  165. $(that.needCloseModal).removeClass('modal-active').addClass('modal-hide');
  166. setTimeout(function() {
  167. $(that.focusEl).focus();
  168. $(that.needCloseModal).css('display', 'none');
  169. that.scrollTo(that.scrollTop);
  170. if (that.scrollThrough) {
  171. $('body').removeClass('modal-open');
  172. } else {
  173. $('body').removeClass('modal-open-scroll-through');
  174. }
  175. $(that.preModal).css('overflow', '');
  176. $('body').css('padding-right', '');
  177. that.closeIng = false;
  178. that.opening = false;
  179. }, that.delayTime);
  180. /*if you need auto play video*/
  181. /*if(document.getElementById(that.preVideo) != null) {
  182. document.getElementById(that.preVideo).pause();
  183. }*/
  184. },
  185. scrollTo: function(num) {
  186. document.body.scrollTop = document.documentElement.scrollTop = num;
  187. },
  188. getScrollTop: function() {
  189. return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  190. },
  191. init: function() {
  192. var that = this;
  193. $('.modal').css('display', 'none');
  194. $('.modal-hide, .modal-hide .modal-wrapper').css('animation-duration', that.delayTime + 'ms');
  195. // 点击关闭按钮或遮罩层关闭当前模态框
  196. $("[data='close'], .modal:not([data-click-mask='false'])").on('click', function() {
  197. that.hide(that.preModal);
  198. });
  199. // 阻止点击触发关闭模态框
  200. $(".modal:not([data-click-mask='false']) .modal-wrapper").on('click', function(e) {
  201. e.stopPropagation();
  202. });
  203. // 点击触发开启模态框
  204. $("[data-type='modal']").on('click', function() {
  205. var target = $(this).attr('data');
  206. /*if you need auto play video*/
  207. /*that.preVideo = $(this).attr('video-data');
  208. if(that.preVideo != null) {
  209. document.getElementById(that.preVideo).play();
  210. }*/
  211. that.open(target);
  212. });
  213. }
  214. };