reload.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // 下载弹窗 设备判断
  2. var ModalHelper = (function (bodyCls) {
  3. var scrollTop;
  4. return {
  5. afterOpen: function () {
  6. scrollTop = document.scrollingElement.scrollTop;
  7. document.body.classList.add(bodyCls);
  8. document.body.style.top = -scrollTop + 'px';
  9. },
  10. beforeClose: function () {
  11. document.body.classList.remove(bodyCls);
  12. // scrollTop lost after set position:fixed, restore it back.
  13. document.scrollingElement.scrollTop = scrollTop;
  14. }
  15. };
  16. })('modal-open');
  17. //显示遮罩层
  18. function showMask() {
  19. document.getElementById("Mask-weChat").style.display = "block";
  20. ModalHelper.afterOpen();
  21. }
  22. //隐藏遮罩层
  23. function hideMask() {
  24. document.getElementById("Mask-weChat").style.display = 'none';
  25. ModalHelper.beforeClose();
  26. }
  27. //ios端显示遮罩层
  28. function showMask2() {
  29. document.getElementById("Mask-IOS").style.display = "block";
  30. document.getElementsByClassName("iosTip-container")[0].style.display = "block";
  31. ModalHelper.afterOpen();
  32. }
  33. //ios端隐藏遮罩层
  34. function hideMask2() {
  35. document.getElementById("Mask-IOS").style.display = 'none';
  36. document.getElementsByClassName("iosTip-container")[0].style.display = 'none';
  37. ModalHelper.beforeClose();
  38. }
  39. //判断设备是否使用微信浏览器打开的
  40. function is_weixn() {
  41. var ua = navigator.userAgent.toLowerCase();
  42. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  43. return true;
  44. } else {
  45. return false;
  46. }
  47. }
  48. //判断是安卓还是iOS
  49. function which_device() {
  50. var u = navigator.userAgent;
  51. var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
  52. var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  53. if (isAndroid) {
  54. return 'Android'
  55. }
  56. if (isiOS) {
  57. return 'iOS'
  58. }
  59. }
  60. $(".download").on("click", function () {
  61. //安卓游戏下载地址
  62. var android_down_url = $(this).find(".android_down_url").html();
  63. //IOS游戏下载地址
  64. var ios_down_url = $(this).find(".ios_down_url").html();
  65. //如果是微信浏览器则提示在浏览器上打开
  66. if (is_weixn() == true) {
  67. showMask();
  68. } else {
  69. if (which_device() == "Android") { //如果设备是安卓则直接下载
  70. if (android_down_url.length !== 0 && android_down_url !== "undefined") {
  71. $(this).find("a").attr("href", android_down_url);
  72. } else {
  73. $.alert("该游戏暂无安卓版本下载<br>请稍后再试", "提示");
  74. }
  75. } else if (which_device() == "iOS") { //如果设备是iOS
  76. //弹出提示遮罩层
  77. showMask2();
  78. if (ios_down_url.length !== 0 && ios_down_url !== "undefined") {
  79. $("#iosdlBtn").attr("href", 'itms-services://?action=download-manifest&url=' + ios_down_url);
  80. } else{
  81. $("#iosdlBtn").attr("href", 'javascript:;');
  82. }
  83. //在遮罩层的其他地方触点就会隐藏遮罩层
  84. document.getElementById("Mask-IOS").onclick = function () {
  85. hideMask2();
  86. }
  87. //点击遮罩层上的【知道了,立即下载】按钮隐藏提示框并且下载
  88. document.getElementById("iosdlBtn").onclick = function () {
  89. document.getElementById('setProcess-wrap').scrollTop = 0;
  90. if (ios_down_url.length !== 0 && ios_down_url !== "undefined") {
  91. // $("#iosdlBtn").attr("href", 'itms-services://?action=download-manifest&url=' + ios_down_url);
  92. } else {
  93. $.alert("该游戏暂无IOS版本下载<br>请稍后再试", "提示");
  94. }
  95. hideMask2();
  96. }
  97. } else {
  98. //除了这两种设备外的,如PC端,还是直接下载安卓的
  99. if (android_down_url.length !== 0 && android_down_url !== "undefined") {
  100. console.log(android_down_url);
  101. $(this).find("a").attr("href", android_down_url);
  102. } else {
  103. $.alert("该游戏暂无安卓版本下载请稍后再试", "提示");
  104. }
  105. }
  106. }
  107. })
  108. //判断是PC还是移动设备 true是PC,false是移动设备
  109. function IsPC() {
  110. var userAgentInfo = navigator.userAgent;
  111. var Agents = ["Android", "iPhone",
  112. "SymbianOS", "Windows Phone",
  113. "iPad", "iPod"
  114. ];
  115. var flag = true;
  116. for (var v = 0; v < Agents.length; v++) {
  117. if (userAgentInfo.indexOf(Agents[v]) > 0) {
  118. flag = false;
  119. break;
  120. }
  121. }
  122. return flag;
  123. }
  124. if (!IsPC()) {
  125. $(".pc").hide();
  126. }
  127. //延迟加载图片
  128. $(function () {
  129. var visible;
  130. $('img').each(function () {
  131. visible = $(this).offset().top - $(window).scrollTop();
  132. if ((visible > 0) && (visible < $(window).height())) {
  133. visible = true;
  134. } else {
  135. visible = false;
  136. }
  137. if (visible) {
  138. $(this).attr('src', $(this).attr('lazy-src'));
  139. }
  140. });
  141. $(window).scroll(function () {
  142. $('img').each(function () {
  143. if ('/static/images/icon/990-625.png' == $(this).attr('src') || '/static/images/icon/150-150.png' == $(this).attr('src') || '/static/images/icon/625-990.png' == $(this).attr('src') || '/static/images/icon/1200-200.png' == $(this).attr('src') || '/static/images/icon/1200-625.png' == $(this).attr('src')) {
  144. visible = $(this).offset().top - $(window).scrollTop();
  145. if ((visible > 0) && (visible < $(window).height())) {
  146. visible = true;
  147. } else {
  148. visible = false;
  149. }
  150. if (visible) {
  151. $(this).attr('src', $(this).attr('lazy-src'));
  152. }
  153. }
  154. });
  155. });
  156. $(".warp-gamelist").scroll(function () {
  157. $('img').each(function () {
  158. if ('/static/images/icon/990-625.png' == $(this).attr('src') || '/static/images/icon/150-150.png' == $(this).attr('src') || '/static/images/icon/625-990.png' == $(this).attr('src') || '/static/images/icon/1200-200.png' == $(this).attr('src') || '/static/images/icon/1200-625.png' == $(this).attr('src')) {
  159. visible = $(this).offset().top - $(window).scrollTop();
  160. if ((visible > 0) && (visible < $(window).height())) {
  161. visible = true;
  162. } else {
  163. visible = false;
  164. }
  165. if (visible) {
  166. $(this).attr('src', $(this).attr('lazy-src'));
  167. }
  168. }
  169. });
  170. });
  171. });
  172. // 设置默认游戏icon
  173. $(".smallIcon").error(function () {
  174. $(this).attr("src", "/static/images/aoyou_game.png");
  175. })
  176. $(".new-img").error(function () {
  177. $(this).attr("src", "/static/images/icon/990_625.png");
  178. })
  179. // 进度条
  180. $(".gift_surplus").each(function () {
  181. var b = $(this).width();
  182. var a = $(this).parent(".warp_gift_surplus").width();
  183. if (a == b) {
  184. $(this).css("border-radius", "8px")
  185. }
  186. })
  187. // 底部位置
  188. var iHigh = document.body.clientHeight;
  189. var aHigh = window.screen.height;
  190. if (aHigh > iHigh) {
  191. $(".footer").addClass("fixed");
  192. }
  193. if ($(".no_content").length > 0) {
  194. var head = $("header").height();
  195. var foot = $('footer').height();
  196. $(".no_content").height(aHigh-head-foot)
  197. }