//菜单栏移入效果 $(function () { $(".public_nav>ul>li").hover(function () { if ($(this).hasClass("current_page")) { } else { $(this).find('span').stop(true, true).animate({ width: "100%" }, 200); } }, function () { if ($(this).hasClass("current_page")) { } else { $(this).find('span').stop(true, true).animate({ width: "0px" }, 200); } }); }) // 头部登录状态下 个人中心弹窗 $(".user_popup").hover(function () { $(".land_popup").show(); }, function () { $(".land_popup").hide(); }); // 去掉ie浏览器 回车键 默认效果 document.onkeydown = function (e) { var e = e || event; if (e.keyCode == 13) { e.preventDefault ? e.preventDefault() : (e.returnValue = false); } } //回到顶部 $(function () { //检测屏幕高度 var height = $(window).height(); height = 3 / 4 * height; //scroll() 方法为滚动事件 $(window).scroll(function () { if ($(window).scrollTop() > height) { $(".hide_top").fadeIn(500); } else { $(".hide_top").fadeOut(500); } }); }); $(".warp_ctlist .totop").click(function () { $("html,body").animate({ scrollTop: '0px' }, 500); }); // 底部弹窗 $(".ad_bottom .close").click(function () { $(".ad_bottom").hide(); $(".footer ul").css("cssText", " padding: 35px 0 !important; "); }); // setTimeout(function () { // if ($(".ad_bottom img").length > 0) { // if ($(".ad_bottom").css("display") == 'none') { // $(".footer ul").css("cssText", " padding: 35px 0 !important;"); // } else { // $(".footer ul").css("cssText", " padding: 35px 0 153px 0 !important;"); // } // } else { // $(".footer ul").css("cssText", " padding: 35px 0 !important;"); // } // }, 1000); // 下载弹窗 $(".az_code img").hover(function () { $(".download_popup .big_az_code").css("cssText", "display: block !important"); }, function () { $(".download_popup .big_az_code").css("cssText", "display: none !important"); }); $(".download_popup .close").click(function () { $(".warp_download_popup").hide(); }); $(".download").click(function () { $(".warp_download_popup").show(); }); $(".tip .close,.determine,.cancel").click(function () { $(".warp_no_download_popup").hide(); $(".warp_kf_popup").hide(); }); $(".no_download").click(function () { $(".warp_no_download_popup").show(); }); // 下载弹窗 $(".small-code").hover(function () { $(this).next().show(); // $(".az_code_right .big_az_code").show(); }, function () { $(this).next().hide(); // $(".az_code_right .big_az_code").hide(); }); $(".rollBox").hover(function () { $(".manu_phone_left").show(); $(".manu_phone_right").show(); }, function () { $(".manu_phone_left").hide(); $(".manu_phone_right").hide(); }); $(".az_hover").hover(function () { $(".az_hover img").attr("src", "/static/images/home/az-white.png"); $(".az_hover span").css("cssText", "color:#fff !important"); }, function () { $(".az_hover img").attr("src", "/static/images/home/SVG-07.png"); $(".az_hover span").css("cssText", "color: #8cc63d !important"); }); // 手游排行控件显示隐藏 $(function () { $('.rank_list>div').eq(0).find('.big').show() $('.rank_list>div').eq(0).find('.small').hide() $('.rank_list').hover(function () { $('.rank_list>div').hover(function () { $(this).find('.big').show().parent().siblings().find('.big').hide(); $(this).find('.small').hide().parent().siblings().find('.small').show(); }); }); }) // 右侧广告 // 最下方两张图片 $(function () { $('.article_adv').hover(function () { $('.article_adv div').stop(true, false).animate({ bottom: 0 }) }, function () { $('.article_adv div').stop(true, false).animate({ bottom: '-28px' }) }); }) // 底部广告关闭不显示 //今日不再显示 $(".ad_bottom .close").click(function () { //当前日期 var curDate = new Date(); //当前时间戳 var curTamp = curDate.getTime(); //当日凌晨的时间戳,减去一毫秒是为了防止后续得到的时间不会达到00:00:00的状态 var curWeeHours = new Date(curDate.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g, '')).getTime() - 1; //当日已经过去的时间(毫秒) var passedTamp = curTamp - curWeeHours; //当日剩余时间 var leftTamp = 24 * 60 * 60 * 1000 - passedTamp; var leftTime = new Date(); leftTime.setTime(leftTamp + curTamp); // 设置cookie document.cookie = 'loginCounta=1;expires=' + leftTime.toGMTString() + ';path=/'; // $("#advert_laye").css("display", "none") }) $(document).ready(function () { var isClosed = /(^|;| )loginCounta=1/.test(document.cookie); //判定cookie是否存在 if (!isClosed) { $(".ad_bottom").css("display", "block") } else { $(".ad_bottom").css("display", "none") } }); // 进度条 $(".gift_surplus").each(function () { var b = $(this).width(); var a = $(this).parent(".warp_gift_surplus").width(); if (a == b) { $(this).css("border-radius", "8px") } }) //延迟加载图片 $(function () { var visible; $('img').each(function () { visible = $(this).offset().top - $(window).scrollTop(); if ((visible > 0) && (visible < $(window).height())) { visible = true; } else { visible = false; } if (visible) { $(this).attr('src', $(this).attr('lazy-src')); } }); $(window).scroll(function () { $('img').each(function () { 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')) { visible = $(this).offset().top - $(window).scrollTop(); if ((visible > 0) && (visible < $(window).height())) { visible = true; } else { visible = false; } if (visible) { $(this).attr('src', $(this).attr('lazy-src')); } } }); }); }); //右侧控件 $(".customer_service ul,.warp_right.warp_qq_icon,.warp_ctlist .qq,.warp_qq").hover(function () { $(".customer_service").show(); $(".warp_qq").stop(true, false).animate({ 'margin-top': '-58px' }, 160) }, function () { $(".customer_service").hide(); $(".warp_qq").stop(true, false).animate({ 'margin-top': '0px' }, 160) }); $(".warp_ctlist .weixin,.warp_right.warp_code,.ctlist .code,.warp_weixin").hover(function () { $(".ctlist .code").show(); $(".warp_weixin").stop(true, false).animate({ 'margin-top': '-58px' }, 160) }, function () { $(".ctlist .code").hide(); $(".warp_weixin").stop(true, false).animate({ 'margin-top': '0px' }, 160) }); $(".customer_service li:first-child+li").hover(function () { $(".border-right-empty span").css("border-left", "10px solid #51a7ff") }, function () { $(".border-right-empty span").css("border-left", "10px solid #f6f6f6") }); $('.warp_totop,.warp_feedback').hover(function () { $(this).stop(true, false).animate({ 'margin-top': '-58px' }, 160) }, function () { $(this).stop(true, false).animate({ 'margin-top': '0px' }, 160) }); $(".qq_1").hover(function () { $(this).find("img").attr("src", "/static/images/home/SVG-16.png"); }, function () { $(this).find("img").attr("src", "/static/images/home/SVG-09.png"); }); // 点击调用方法,弹出对话框 $(".customer_service li").on("click", "a", function () { openQQ($(this).attr("data-QQ")); }) // 打开对话框的方法 function openQQ(qq) { window.location.href = "tencent://message/?uin=" + qq + "&Site=&Menu=yes"; } // 设置默认游戏icon $(".smallIcon").error(function () { $(this).attr("src", "/static/images/icon/150-150.png"); }) // 分页 $(function () { $(".pagination li:first-child a").html('上一页'); $(".pagination li:first-child span").html('上一页'); $(".pagination li:last-child a").html('下一页'); $(".pagination li:last-child span").html('下一页'); }); $(".disabled").each(function(){ var a = $(this).text(); if(a="..."){ //修改父元素 $(this).find("span").css("cssText", "background:#fff;color:#494949 !important;border:none;cursor: context-menu;"); } }) // 退出登录 function toExit() { $.ajax({ type: 'POST', url: '/member/logout', data: {}, dataType: 'json', success: function (json) { window.location.reload(); }, error: function () { alert('网络错误,请刷新页面重试'); } }); } // 搜索框 $('body').bind('click', function (event) { // IE支持 event.srcElement , FF支持 event.target var evt = event.srcElement ? event.srcElement : event.target; if (evt.id == 'search-input'|| evt.id == 'delete') { var a = $('#search-input').val(); if (a == "") { // $("#search_ul").hide(); update_history(); } else if ($("#search_ul li").length > 0) { $("#search_ul").show(); } } else { $('#search ul ').hide(); // 如不是则隐藏元素 } }); $("#search_result").click(function () { var vala = $("#search-input").val(); if (vala == "") { vala = $("#search-input").attr('placeholder'); $("#search_ul").hide(); } else if ($("#search_ul li").length > 0) { $("#search_ul").show(); } var search = "/search/keyword/" + vala; $("#search_result").attr("href", search); }) // 去掉ie回车键默认作用 document.onkeydown = function (e) { var e = e || event; if (e.keyCode == 13) { e.preventDefault ? e.preventDefault() : (e.returnValue = false); } } var flag = true; $('#search-input').on('compositionstart', function () { flag = false; }) $('#search-input').on('compositionend', function () { flag = true; }) var search = { searchKeyword: function () { val = String($('#search-input').val()) val = val.replace(/\s*/g, ""); vala = $('#search-input').val(); if (vala == "") { vala = $("#search-input").attr('placeholder'); // $("#search_ul").hide(); update_history(); } else if ($("#search_ul li").length > 0) { $("#search_ul").show(); } var search = "/search/keyword/" + vala; $("#search_result").attr("href", search); // 按回车搜索 var e = event || window.event || arguments.callee.caller.arguments[0]; if (e && e.keyCode == 13) { // enter 键 document.getElementById("search_result").click(); } setTimeout(function () { if (flag) { if (!val.length || val.length == 0 || vala == " ") { // $("#search_ul").hide(); // $("#search_ul").empty(); update_history(); return } $.ajax({ type: 'POST', url: '/game/ajaxGameList', dataType: 'json', data: { keyword: val }, success: function (json) { if ($.isEmptyObject(json)) { $("#search_ul").empty(); $("#search_ul").hide(); } else { var html = '', turl = '/game101'; $.each(json, function (i, row) { toUrl = turl.replace('101', row.id) html += '
  • ' + row.nickname + '
  • '; }); arrow = '
    ' $("#search_ul").html(html + arrow); $("#search_ul").show(); } } }); } }, 10) } } // 搜索框历史记录 $(function(){ // 搜索点击事件 $("#search_result").click(function(){ var keywords = $("#search-input").val(); keywords= keywords.replace(/\s*/g, ""); if ( keywords == "") { keywords = $("#search-input").attr('placeholder'); } historya(keywords); //添加到缓存 update_history(); //更新搜索历史 }) }) /** * [update_history 更新搜索历史] * @return {[type]} [description] */ function update_history(){ console.log(mystorage.get("keywords")); var history = mystorage.get("keywords"); if (history) { var html = ""; $.each(history,function(i,v){ var url = "/search/keyword/"+ v; html += '
  • '+v+'
  • ' }) arrow = '
    ' $("#search_ul").html(html + arrow); }; if($("#search_ul li").length ==0){ $("#search_ul").hide(); }else{ $("#search_ul").show(); } // 点击删除历史 $(".delete").click(function(){ var tqtest = $(this).prev().html(); var history = mystorage.get("keywords"); history.splice($.inArray(tqtest,history),1); mystorage.set("keywords",history); // $(this).parents("li").remove(); update_history(); }) } /** * [history //搜索历史函数存储] * @param {[type]} value [搜索词] * @return {[type]} [description] */ function historya(value){ var data = mystorage.get("keywords"); if (!data) { var data = []; //定义一个空数组 }else if(data.length === 10){ //搜索历史数量 data.pop(); //删除数组最后一个元素 }else{ }; if (value) { //判断搜索词是否为空 if (data.indexOf(value)<0) { //判断搜索词是否存在数组中 // data.push(value); //搜索词添加到数组中 data.splice(0, 0,value); //搜索词添加到数组第一个位置 mystorage.set("keywords",data); //存储到本地化存储中 }else{ data.splice($.inArray(value,data),1); data.splice(0, 0,value); //搜索词添加到数组第一个位置 mystorage.set("keywords",data); //存储到本地化存储中 }; }; } /** * [mystorage 存储localstorage时候最好是封装一个自己的键值,在这个值里存储自己的内容对象,封装一个方法针对自己对象进行操作。避免冲突也会在开发中更方便。] * @param {String} ){ var ms [description] * @return {[type]} [description] console.log(mystorage.set('tqtest','tqtestcontent'));//存储 console.log(mystorage.set('aa','123'));//存储 console.log(mystorage.set('tqtest1','tqtestcontent1'));//存储 console.log(mystorage.set('tqtest1','newtqtestcontent1'));//修改 console.log(mystorage.get('tqtest'));//读取 console.log(mystorage.remove('tqtest'));//删除 mystorage.clear();//整体清除 */ var mystorage = (function mystorage(){ var ms = "mystorage"; var storage=window.localStorage; if(!window.localStorage){ alert("浏览器不支持localstorage"); return false; } var set = function(key,value){ //存储 var mydata = storage.getItem(ms); if(!mydata){ this.init(); mydata = storage.getItem(ms); } mydata = JSON.parse(mydata); mydata.data[key] = value; storage.setItem(ms,JSON.stringify(mydata)); return mydata.data; }; var get = function(key){ //读取 var mydata = storage.getItem(ms); if(!mydata){ return false; } mydata = JSON.parse(mydata); return mydata.data[key]; }; var remove = function(key){ //读取 var mydata = storage.getItem(ms); if(!mydata){ return false; } mydata = JSON.parse(mydata); delete mydata.data[key]; storage.setItem(ms,JSON.stringify(mydata)); return mydata.data; }; var clear = function(){ //清除对象 storage.removeItem(ms); }; var init = function(){ storage.setItem(ms,'{"data":{}}'); }; return { set : set, get : get, remove : remove, init : init, clear : clear }; })();