// 下载弹窗 设备判断
var ModalHelper = (function (bodyCls) {
var scrollTop;
return {
afterOpen: function () {
scrollTop = document.scrollingElement.scrollTop;
document.body.classList.add(bodyCls);
document.body.style.top = -scrollTop + 'px';
},
beforeClose: function () {
document.body.classList.remove(bodyCls);
// scrollTop lost after set position:fixed, restore it back.
document.scrollingElement.scrollTop = scrollTop;
}
};
})('modal-open');
//显示遮罩层
function showMask() {
document.getElementById("Mask-weChat").style.display = "block";
ModalHelper.afterOpen();
}
//隐藏遮罩层
function hideMask() {
document.getElementById("Mask-weChat").style.display = 'none';
ModalHelper.beforeClose();
}
//ios端显示遮罩层
function showMask2() {
document.getElementById("Mask-IOS").style.display = "block";
document.getElementsByClassName("iosTip-container")[0].style.display = "block";
ModalHelper.afterOpen();
}
//ios端隐藏遮罩层
function hideMask2() {
document.getElementById("Mask-IOS").style.display = 'none';
document.getElementsByClassName("iosTip-container")[0].style.display = 'none';
ModalHelper.beforeClose();
}
//判断设备是否使用微信浏览器打开的
function is_weixn() {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
} else {
return false;
}
}
//判断是安卓还是iOS
function which_device() {
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if (isAndroid) {
return 'Android'
}
if (isiOS) {
return 'iOS'
}
}
$(".download").on("click", function () {
//安卓游戏下载地址
var android_down_url = $(this).find(".android_down_url").html();
//IOS游戏下载地址
var ios_down_url = $(this).find(".ios_down_url").html();
//如果是微信浏览器则提示在浏览器上打开
if (is_weixn() == true) {
showMask();
} else {
if (which_device() == "Android") { //如果设备是安卓则直接下载
if (android_down_url.length !== 0 && android_down_url !== "undefined") {
$(this).find("a").attr("href", android_down_url);
} else {
$.alert("该游戏暂无安卓版本下载
请稍后再试", "提示");
}
} else if (which_device() == "iOS") { //如果设备是iOS
//弹出提示遮罩层
showMask2();
if (ios_down_url.length !== 0 && ios_down_url !== "undefined") {
$("#iosdlBtn").attr("href", 'itms-services://?action=download-manifest&url=' + ios_down_url);
} else{
$("#iosdlBtn").attr("href", 'javascript:;');
}
//在遮罩层的其他地方触点就会隐藏遮罩层
document.getElementById("Mask-IOS").onclick = function () {
hideMask2();
}
//点击遮罩层上的【知道了,立即下载】按钮隐藏提示框并且下载
document.getElementById("iosdlBtn").onclick = function () {
document.getElementById('setProcess-wrap').scrollTop = 0;
if (ios_down_url.length !== 0 && ios_down_url !== "undefined") {
// $("#iosdlBtn").attr("href", 'itms-services://?action=download-manifest&url=' + ios_down_url);
} else {
$.alert("该游戏暂无IOS版本下载
请稍后再试", "提示");
}
hideMask2();
}
} else {
//除了这两种设备外的,如PC端,还是直接下载安卓的
if (android_down_url.length !== 0 && android_down_url !== "undefined") {
console.log(android_down_url);
$(this).find("a").attr("href", android_down_url);
} else {
$.alert("该游戏暂无安卓版本下载请稍后再试", "提示");
}
}
}
})
//判断是PC还是移动设备 true是PC,false是移动设备
function IsPC() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone",
"SymbianOS", "Windows Phone",
"iPad", "iPod"
];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
if (!IsPC()) {
$(".pc").hide();
}
//延迟加载图片
$(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'));
}
}
});
});
$(".warp-gamelist").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'));
}
}
});
});
});
// 设置默认游戏icon
$(".smallIcon").error(function () {
$(this).attr("src", "/static/images/aoyou_game.png");
})
$(".new-img").error(function () {
$(this).attr("src", "/static/images/icon/990_625.png");
})
// 进度条
$(".gift_surplus").each(function () {
var b = $(this).width();
var a = $(this).parent(".warp_gift_surplus").width();
if (a == b) {
$(this).css("border-radius", "8px")
}
})
// 底部位置
var iHigh = document.body.clientHeight;
var aHigh = window.screen.height;
if (aHigh > iHigh) {
$(".footer").addClass("fixed");
}
if ($(".no_content").length > 0) {
var head = $("header").height();
var foot = $('footer').height();
$(".no_content").height(aHigh-head-foot)
}