common.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. //菜单栏移入效果
  2. $(function () {
  3. $(".public_nav>ul>li").hover(function () {
  4. if ($(this).hasClass("current_page")) {
  5. } else {
  6. $(this).find('span').stop(true, true).animate({ width: "100%" }, 200);
  7. }
  8. }, function () {
  9. if ($(this).hasClass("current_page")) {
  10. } else {
  11. $(this).find('span').stop(true, true).animate({ width: "0px" }, 200);
  12. }
  13. });
  14. })
  15. // 头部登录状态下 个人中心弹窗
  16. $(".user_popup").hover(function () {
  17. $(".land_popup").show();
  18. }, function () {
  19. $(".land_popup").hide();
  20. });
  21. // 去掉ie浏览器 回车键 默认效果
  22. document.onkeydown = function (e) {
  23. var e = e || event;
  24. if (e.keyCode == 13) {
  25. e.preventDefault ? e.preventDefault() : (e.returnValue = false);
  26. }
  27. }
  28. //回到顶部
  29. $(function () {
  30. //检测屏幕高度
  31. var height = $(window).height();
  32. height = 3 / 4 * height;
  33. //scroll() 方法为滚动事件
  34. $(window).scroll(function () {
  35. if ($(window).scrollTop() > height) {
  36. $(".hide_top").fadeIn(500);
  37. } else {
  38. $(".hide_top").fadeOut(500);
  39. }
  40. });
  41. });
  42. $(".warp_ctlist .totop").click(function () {
  43. $("html,body").animate({ scrollTop: '0px' }, 500);
  44. });
  45. // 底部弹窗
  46. $(".ad_bottom .close").click(function () {
  47. $(".ad_bottom").hide();
  48. $(".footer ul").css("cssText", " padding: 35px 0 !important; ");
  49. });
  50. // setTimeout(function () {
  51. // if ($(".ad_bottom img").length > 0) {
  52. // if ($(".ad_bottom").css("display") == 'none') {
  53. // $(".footer ul").css("cssText", " padding: 35px 0 !important;");
  54. // } else {
  55. // $(".footer ul").css("cssText", " padding: 35px 0 153px 0 !important;");
  56. // }
  57. // } else {
  58. // $(".footer ul").css("cssText", " padding: 35px 0 !important;");
  59. // }
  60. // }, 1000);
  61. // 下载弹窗
  62. $(".az_code img").hover(function () {
  63. $(".download_popup .big_az_code").css("cssText", "display: block !important");
  64. }, function () {
  65. $(".download_popup .big_az_code").css("cssText", "display: none !important");
  66. });
  67. $(".download_popup .close").click(function () {
  68. $(".warp_download_popup").hide();
  69. });
  70. $(".download").click(function () {
  71. $(".warp_download_popup").show();
  72. });
  73. $(".tip .close,.determine,.cancel").click(function () {
  74. $(".warp_no_download_popup").hide();
  75. $(".warp_kf_popup").hide();
  76. });
  77. $(".no_download").click(function () {
  78. $(".warp_no_download_popup").show();
  79. });
  80. // 下载弹窗
  81. $(".small-code").hover(function () {
  82. $(this).next().show();
  83. // $(".az_code_right .big_az_code").show();
  84. }, function () {
  85. $(this).next().hide();
  86. // $(".az_code_right .big_az_code").hide();
  87. });
  88. $(".rollBox").hover(function () {
  89. $(".manu_phone_left").show();
  90. $(".manu_phone_right").show();
  91. }, function () {
  92. $(".manu_phone_left").hide();
  93. $(".manu_phone_right").hide();
  94. });
  95. $(".az_hover").hover(function () {
  96. $(".az_hover img").attr("src", "/static/images/home/az-white.png");
  97. $(".az_hover span").css("cssText", "color:#fff !important");
  98. }, function () {
  99. $(".az_hover img").attr("src", "/static/images/home/SVG-07.png");
  100. $(".az_hover span").css("cssText", "color: #8cc63d !important");
  101. });
  102. // 手游排行控件显示隐藏
  103. $(function () {
  104. $('.rank_list>div').eq(0).find('.big').show()
  105. $('.rank_list>div').eq(0).find('.small').hide()
  106. $('.rank_list').hover(function () {
  107. $('.rank_list>div').hover(function () {
  108. $(this).find('.big').show().parent().siblings().find('.big').hide();
  109. $(this).find('.small').hide().parent().siblings().find('.small').show();
  110. });
  111. });
  112. })
  113. // 右侧广告
  114. // 最下方两张图片
  115. $(function () {
  116. $('.article_adv').hover(function () {
  117. $('.article_adv div').stop(true, false).animate({
  118. bottom: 0
  119. })
  120. }, function () {
  121. $('.article_adv div').stop(true, false).animate({
  122. bottom: '-28px'
  123. })
  124. });
  125. })
  126. // 底部广告关闭不显示
  127. //今日不再显示
  128. $(".ad_bottom .close").click(function () {
  129. //当前日期
  130. var curDate = new Date();
  131. //当前时间戳
  132. var curTamp = curDate.getTime();
  133. //当日凌晨的时间戳,减去一毫秒是为了防止后续得到的时间不会达到00:00:00的状态
  134. var curWeeHours = new Date(curDate.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g, '')).getTime() - 1;
  135. //当日已经过去的时间(毫秒)
  136. var passedTamp = curTamp - curWeeHours;
  137. //当日剩余时间
  138. var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;
  139. var leftTime = new Date();
  140. leftTime.setTime(leftTamp + curTamp);
  141. // 设置cookie
  142. document.cookie = 'loginCounta=1;expires=' + leftTime.toGMTString() + ';path=/';
  143. // $("#advert_laye").css("display", "none")
  144. })
  145. $(document).ready(function () {
  146. var isClosed = /(^|;| )loginCounta=1/.test(document.cookie); //判定cookie是否存在
  147. if (!isClosed) {
  148. $(".ad_bottom").css("display", "block")
  149. } else {
  150. $(".ad_bottom").css("display", "none")
  151. }
  152. });
  153. // 进度条
  154. $(".gift_surplus").each(function () {
  155. var b = $(this).width();
  156. var a = $(this).parent(".warp_gift_surplus").width();
  157. if (a == b) {
  158. $(this).css("border-radius", "8px")
  159. }
  160. })
  161. //延迟加载图片
  162. $(function () {
  163. var visible;
  164. $('img').each(function () {
  165. visible = $(this).offset().top - $(window).scrollTop();
  166. if ((visible > 0) && (visible < $(window).height())) {
  167. visible = true;
  168. } else {
  169. visible = false;
  170. }
  171. if (visible) {
  172. $(this).attr('src', $(this).attr('lazy-src'));
  173. }
  174. });
  175. $(window).scroll(function () {
  176. $('img').each(function () {
  177. 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')) {
  178. visible = $(this).offset().top - $(window).scrollTop();
  179. if ((visible > 0) && (visible < $(window).height())) {
  180. visible = true;
  181. } else {
  182. visible = false;
  183. }
  184. if (visible) {
  185. $(this).attr('src', $(this).attr('lazy-src'));
  186. }
  187. }
  188. });
  189. });
  190. });
  191. //右侧控件
  192. $(".customer_service ul,.warp_right.warp_qq_icon,.warp_ctlist .qq,.warp_qq").hover(function () {
  193. $(".customer_service").show();
  194. $(".warp_qq").stop(true, false).animate({ 'margin-top': '-58px' }, 160)
  195. }, function () {
  196. $(".customer_service").hide();
  197. $(".warp_qq").stop(true, false).animate({ 'margin-top': '0px' }, 160)
  198. });
  199. $(".warp_ctlist .weixin,.warp_right.warp_code,.ctlist .code,.warp_weixin").hover(function () {
  200. $(".ctlist .code").show();
  201. $(".warp_weixin").stop(true, false).animate({ 'margin-top': '-58px' }, 160)
  202. }, function () {
  203. $(".ctlist .code").hide();
  204. $(".warp_weixin").stop(true, false).animate({ 'margin-top': '0px' }, 160)
  205. });
  206. $(".customer_service li:first-child+li").hover(function () {
  207. $(".border-right-empty span").css("border-left", "10px solid #51a7ff")
  208. }, function () {
  209. $(".border-right-empty span").css("border-left", "10px solid #f6f6f6")
  210. });
  211. $('.warp_totop,.warp_feedback').hover(function () {
  212. $(this).stop(true, false).animate({
  213. 'margin-top': '-58px'
  214. }, 160)
  215. }, function () {
  216. $(this).stop(true, false).animate({
  217. 'margin-top': '0px'
  218. }, 160)
  219. });
  220. $(".qq_1").hover(function () {
  221. $(this).find("img").attr("src", "/static/images/home/SVG-16.png");
  222. }, function () {
  223. $(this).find("img").attr("src", "/static/images/home/SVG-09.png");
  224. });
  225. // 点击调用方法,弹出对话框
  226. $(".customer_service li").on("click", "a", function () {
  227. openQQ($(this).attr("data-QQ"));
  228. })
  229. // 打开对话框的方法
  230. function openQQ(qq) {
  231. window.location.href = "tencent://message/?uin=" + qq + "&Site=&Menu=yes";
  232. }
  233. // 设置默认游戏icon
  234. $(".smallIcon").error(function () {
  235. $(this).attr("src", "/static/images/icon/150-150.png");
  236. })
  237. // 分页
  238. $(function () {
  239. $(".pagination li:first-child a").html('上一页');
  240. $(".pagination li:first-child span").html('上一页');
  241. $(".pagination li:last-child a").html('下一页');
  242. $(".pagination li:last-child span").html('下一页');
  243. });
  244. $(".disabled").each(function(){
  245. var a = $(this).text();
  246. if(a="..."){
  247. //修改父元素
  248. $(this).find("span").css("cssText", "background:#fff;color:#494949 !important;border:none;cursor: context-menu;");
  249. }
  250. })
  251. // 退出登录
  252. function toExit() {
  253. $.ajax({
  254. type: 'POST',
  255. url: '/member/logout',
  256. data: {},
  257. dataType: 'json',
  258. success: function (json) {
  259. window.location.reload();
  260. },
  261. error: function () {
  262. alert('网络错误,请刷新页面重试');
  263. }
  264. });
  265. }
  266. // 搜索框
  267. $('body').bind('click', function (event) {
  268. // IE支持 event.srcElement , FF支持 event.target
  269. var evt = event.srcElement ? event.srcElement : event.target;
  270. if (evt.id == 'search-input'|| evt.id == 'delete') {
  271. var a = $('#search-input').val();
  272. if (a == "") {
  273. // $("#search_ul").hide();
  274. update_history();
  275. } else if ($("#search_ul li").length > 0) {
  276. $("#search_ul").show();
  277. }
  278. }
  279. else {
  280. $('#search ul ').hide(); // 如不是则隐藏元素
  281. }
  282. });
  283. $("#search_result").click(function () {
  284. var vala = $("#search-input").val();
  285. if (vala == "") {
  286. vala = $("#search-input").attr('placeholder');
  287. $("#search_ul").hide();
  288. } else if ($("#search_ul li").length > 0) {
  289. $("#search_ul").show();
  290. }
  291. var search = "/search/keyword/" + vala;
  292. $("#search_result").attr("href", search);
  293. })
  294. // 去掉ie回车键默认作用
  295. document.onkeydown = function (e) {
  296. var e = e || event;
  297. if (e.keyCode == 13) {
  298. e.preventDefault ? e.preventDefault() : (e.returnValue = false);
  299. }
  300. }
  301. var flag = true;
  302. $('#search-input').on('compositionstart', function () {
  303. flag = false;
  304. })
  305. $('#search-input').on('compositionend', function () {
  306. flag = true;
  307. })
  308. var search = {
  309. searchKeyword: function () {
  310. val = String($('#search-input').val())
  311. val = val.replace(/\s*/g, "");
  312. vala = $('#search-input').val();
  313. if (vala == "") {
  314. vala = $("#search-input").attr('placeholder');
  315. // $("#search_ul").hide();
  316. update_history();
  317. } else if ($("#search_ul li").length > 0) {
  318. $("#search_ul").show();
  319. }
  320. var search = "/search/keyword/" + vala;
  321. $("#search_result").attr("href", search);
  322. // 按回车搜索
  323. var e = event || window.event || arguments.callee.caller.arguments[0];
  324. if (e && e.keyCode == 13) { // enter 键
  325. document.getElementById("search_result").click();
  326. }
  327. setTimeout(function () {
  328. if (flag) {
  329. if (!val.length || val.length == 0 || vala == " ") {
  330. // $("#search_ul").hide();
  331. // $("#search_ul").empty();
  332. update_history();
  333. return
  334. }
  335. $.ajax({
  336. type: 'POST',
  337. url: '/game/ajaxGameList',
  338. dataType: 'json',
  339. data: { keyword: val },
  340. success: function (json) {
  341. if ($.isEmptyObject(json)) {
  342. $("#search_ul").empty();
  343. $("#search_ul").hide();
  344. } else {
  345. var html = '',
  346. turl = '/game101';
  347. $.each(json, function (i, row) {
  348. toUrl = turl.replace('101', row.id)
  349. html += '<li><a href="' + toUrl + '" target="_blank">' + row.nickname + '</a></li>';
  350. });
  351. arrow = ' <div class="border-up-empty"> <span></span></div>'
  352. $("#search_ul").html(html + arrow);
  353. $("#search_ul").show();
  354. }
  355. }
  356. });
  357. }
  358. }, 10)
  359. }
  360. }
  361. // 搜索框历史记录
  362. $(function(){
  363. // 搜索点击事件
  364. $("#search_result").click(function(){
  365. var keywords = $("#search-input").val();
  366. keywords= keywords.replace(/\s*/g, "");
  367. if ( keywords == "") {
  368. keywords = $("#search-input").attr('placeholder');
  369. }
  370. historya(keywords); //添加到缓存
  371. update_history(); //更新搜索历史
  372. })
  373. })
  374. /**
  375. * [update_history 更新搜索历史]
  376. * @return {[type]} [description]
  377. */
  378. function update_history(){
  379. console.log(mystorage.get("keywords"));
  380. var history = mystorage.get("keywords");
  381. if (history) {
  382. var html = "";
  383. $.each(history,function(i,v){
  384. var url = "/search/keyword/"+ v;
  385. html += '<li><a href="'+url+'" target="_blank">'+v+'</a><img src="/static/images/mobile/icon/close-gray.png" class="delete" id="delete"> </li>'
  386. })
  387. arrow = ' <div class="border-up-empty"><span></span></div>'
  388. $("#search_ul").html(html + arrow);
  389. };
  390. if($("#search_ul li").length ==0){
  391. $("#search_ul").hide();
  392. }else{
  393. $("#search_ul").show();
  394. }
  395. // 点击删除历史
  396. $(".delete").click(function(){
  397. var tqtest = $(this).prev().html();
  398. var history = mystorage.get("keywords");
  399. history.splice($.inArray(tqtest,history),1);
  400. mystorage.set("keywords",history);
  401. // $(this).parents("li").remove();
  402. update_history();
  403. })
  404. }
  405. /**
  406. * [history //搜索历史函数存储]
  407. * @param {[type]} value [搜索词]
  408. * @return {[type]} [description]
  409. */
  410. function historya(value){
  411. var data = mystorage.get("keywords");
  412. if (!data) {
  413. var data = []; //定义一个空数组
  414. }else if(data.length === 10){ //搜索历史数量
  415. data.pop(); //删除数组最后一个元素
  416. }else{
  417. };
  418. if (value) { //判断搜索词是否为空
  419. if (data.indexOf(value)<0) { //判断搜索词是否存在数组中
  420. // data.push(value); //搜索词添加到数组中
  421. data.splice(0, 0,value); //搜索词添加到数组第一个位置
  422. mystorage.set("keywords",data); //存储到本地化存储中
  423. }else{
  424. data.splice($.inArray(value,data),1);
  425. data.splice(0, 0,value); //搜索词添加到数组第一个位置
  426. mystorage.set("keywords",data); //存储到本地化存储中
  427. };
  428. };
  429. }
  430. /**
  431. * [mystorage 存储localstorage时候最好是封装一个自己的键值,在这个值里存储自己的内容对象,封装一个方法针对自己对象进行操作。避免冲突也会在开发中更方便。]
  432. * @param {String} ){ var ms [description]
  433. * @return {[type]} [description]
  434. console.log(mystorage.set('tqtest','tqtestcontent'));//存储
  435. console.log(mystorage.set('aa','123'));//存储
  436. console.log(mystorage.set('tqtest1','tqtestcontent1'));//存储
  437. console.log(mystorage.set('tqtest1','newtqtestcontent1'));//修改
  438. console.log(mystorage.get('tqtest'));//读取
  439. console.log(mystorage.remove('tqtest'));//删除
  440. mystorage.clear();//整体清除
  441. */
  442. var mystorage = (function mystorage(){
  443. var ms = "mystorage";
  444. var storage=window.localStorage;
  445. if(!window.localStorage){
  446. alert("浏览器不支持localstorage");
  447. return false;
  448. }
  449. var set = function(key,value){
  450. //存储
  451. var mydata = storage.getItem(ms);
  452. if(!mydata){
  453. this.init();
  454. mydata = storage.getItem(ms);
  455. }
  456. mydata = JSON.parse(mydata);
  457. mydata.data[key] = value;
  458. storage.setItem(ms,JSON.stringify(mydata));
  459. return mydata.data;
  460. };
  461. var get = function(key){
  462. //读取
  463. var mydata = storage.getItem(ms);
  464. if(!mydata){
  465. return false;
  466. }
  467. mydata = JSON.parse(mydata);
  468. return mydata.data[key];
  469. };
  470. var remove = function(key){
  471. //读取
  472. var mydata = storage.getItem(ms);
  473. if(!mydata){
  474. return false;
  475. }
  476. mydata = JSON.parse(mydata);
  477. delete mydata.data[key];
  478. storage.setItem(ms,JSON.stringify(mydata));
  479. return mydata.data;
  480. };
  481. var clear = function(){
  482. //清除对象
  483. storage.removeItem(ms);
  484. };
  485. var init = function(){
  486. storage.setItem(ms,'{"data":{}}');
  487. };
  488. return {
  489. set : set,
  490. get : get,
  491. remove : remove,
  492. init : init,
  493. clear : clear
  494. };
  495. })();