var scale = 1;
var logoh, maxh = 600;
var isfirefox = false;
var logopath = "https://www.gzarts.edu.cn/2023images/svgg/";
var resizeTimer = null;
var ticking = false;
var isinit = true;
var max = 62;
$(function () {
loadsvg();
resetEngDate();
updateRightMenuHeight();
$(".cross").click(function () {
$(this).toggleClass("on")
$(".right-menu").toggleClass("on")
})
$(".nav ul>li").hover(function () {
$(this).find(".submenu").stop(true, true)
if ($(this).find("a").hasClass("on")) return;
$(this).find("a").addClass("on")
$(this).find(".submenu").slideDown(180);
}, function () {
$(this).find(".submenu").stop(true, true)
if ($(this).find("a").hasClass("on")) {
$(this).find("a").removeClass("on")
$(this).find(".submenu").slideUp(180);
}
})
// $("#home-header").css("zoom", delta);
logoh = 600;
if ($("#home-header").length > 0) {
//主页事件
$("#home-bottom li").each(function () {
var that = this;
var ele_ul = $(that).find(".bottom-subnav");
$(that).click(function () {
$(that).find(".circle-btn").toggleClass("on");
if ($(that).find(".circle-btn").hasClass("on")) {
$(ele_ul).slideUp(180);
} else {
$(ele_ul).slideDown(180);
$(that).siblings().find(".bottom-subnav").slideUp(180);
$(that).siblings().find(".circle-btn").addClass("on");
}
})
})
updateHeaderScale();
setlogo();
// initlogo();
$(window).scroll(function () {
setlogo();
});
// setlogo()
initNewsItem();
initHomeBottomNav();
$(window).resize(function () {
updateNewsItem();
updateBottomNav();
updateRightMenuHeight();
updateHeaderScale();
setlogo();
});
} else if ($("#sub-header").length > 0) {
logoh = 280;
//二级页面事件
updateHeaderScale();
setsublogo();
// initlogo();
// $("#enter-circle img").css("width", $("#enter-circle img").width()+"px");
$("#enter-circle").fadeOut(800);
if ($("#subpage-bottom").length > 0) {
var subCounter = $("#subpage-bottom .bottom-nav>li").length;
$("#subpage-bottom .bottom-nav>li").css("width", 100 / subCounter + "%");
if ($("#ajax-nav").length == 0) {
$("#subpage-bottom .bottom-nav>li").each(function () {
$(this).click(function () {
if ($(this).find("ul").hasClass("on")) {
$(this).find("ul").slideUp();
} else {
$(this).find("ul").slideDown();
$(this).siblings().find("ul").slideUp();
$(this).siblings().find("ul").removeClass("on")
}
$(this).find("ul").toggleClass("on");
})
})
}
}
// setsublogo();
$(window).resize(function () {
updateRightMenuHeight();
updateHeaderScale();
setsublogo();
});
$(window).scroll(function () {
setsublogo();
});
}
$(window).scroll(function () {
var h = $(".root").offset().top - $(window).scrollTop();
if (h <= 0) {
hideLogo();
}
else
showLogo()
});
updateBottomNav();
if ($(".p_prev_d a").length == 0) {
$(".p_prev_d").hide();
}
if ($(".p_prev_d a").length == 0) {
$(".p_prev_d").hide();
}
if ($(".p_last a").length == 0) {
$(".p_last").hide();
}
$(".p_next a").text('');
$(".p_next a").text('');
$(".p_prev a").text('');
//滚动到屏幕上方
setTimeout(function () {
$(window).scrollTop(0);
$(".logoheader").css("opacity", 1);
}, 200);
});
function hideLogo () {
$(".page-top").addClass("fix");
$("#main").addClass("fix");
}
function setlogo () {
var h = $(".root").offset().top - $(window).scrollTop();
if (h < 0 || Math.ceil(h) > Math.ceil(maxh)) return;
$(".gafa").css("height", h + "px")
var del = h / maxh;
var padh = 50 * del * scale;
$("#gafa-home").css("padding-top", padh + "px");
$("#gafa-home").css("padding-bottom", padh + "px");
var letterheight = h - 100 * del * scale;
var num = Math.floor(2 * max * (Math.floor(maxh) - Math.floor(h)) / maxh);
if (num <= 0) num = 1;
if (num > 2 * max) num = max;
if (num >= 0 && num <= 2 * max) {
// var newh = 700 * 500 / 518;
var newh = 700 * letterheight / 518;
$("#g").css('height', newh + "px");
$("#g").css("width", newh + "px");
// $("#g").css("left", "-" + 50 * scale * newh / 700 + "px")
var orih = 700 * maxh / 600;
$("#g").css("left", "-" + 55 * scale * newh / orih + "px")
var pos = (num % max);
$("#g-" + pos).css("opacity", 1);
$("#g-" + pos).siblings().css("opacity", 0);
}
$(".a").css("width", $(".a img").width());
}
function setsublogo () {
var h = $(".root").offset().top - $(window).scrollTop();
// var maxh = 280;
var num = Math.floor(2 * max * (Math.floor(maxh) - Math.floor(h)) / maxh);
var del = h / logoh;
var padh = 25 * del * scale;
var letterheight = h - padh * 2;
$("#gafa-sub").css("padding-top", padh + "px");
$("#gafa-sub").css("padding-bottom", padh + "px");
$(".gafa").css("height", h + "px")
if (num <= 0) num = 1;
if (num > 2 * max) num = max;
if (num >= 0 && num <= 2 * max) {
// var newh = 700 * 230 / 518;
//if (h < maxh)
var newh = 700 * letterheight / 518;
// if (isfirefox) {
// newh = newh / scale;
// }
$("#g").css('height', newh + "px");
$("#g").css("width", newh + "px");
var orih = 700 * maxh / 280;
$("#g").css("left", "-" + 55 * scale * newh / orih + "px")
var pos = (num % max);
$("#g-" + pos).css("opacity", 1);
$("#g-" + pos).siblings().css("opacity", 0);
}
$(".a").css("width", $(".a img").width());
}
function showLogo () {
$(".page-top").removeClass("fix");
$("#main").removeClass("fix");
$(".root").removeClass("fix");
}
function pad (str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
function updateBottomNav () {
var wh = $(window).height();
$("#home-bottom .bottom-nav li .bottom-subnav").each(function (index, obj) {
$(obj).css("height", wh + "px")
})
}
function updateRightMenuHeight () {
var wh = $(window).height();
$(".right-menu").css("height", (wh - 51 - $(".page-bottom").height()) + "px");
}
function updateNewsItem () {
//resize时
var w = calcW();
var colen = caclCol(w);
var orilen = $(".main .right>div").length;
if (colen == orilen + 2) {
calcCircleSize(colen);
return;
};
if (resizeTimer)
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function () {
requestTick();
}, 100);
}
function calcW () {
return $(window).width() - 24;
}
function caclCol (w) {
return Math.ceil(w / 300);
}
function appendCol (colen) {
var orilen = $(".main .right>div").length;
if (colen >= orilen + 2) {
for (var i = orilen + 3; i <= colen; i++) {
var newdiv = $("
").attr("class", "newscol col" + i)
$(".main .right").append(newdiv);
}
}
}
function update () {
var w = calcW();
var colen = caclCol(w);
var orilen = $(".main .right>div").length;
$(".main .small").removeClass("sorted");
if (colen > orilen + 2) {
//扩展的
appendCol(colen);
for (var i = 1; i <= $(".main .small").length; i++) {
var item = $("#data-" + i);
// if (i <= orilen) {
// $("#data-" + i).addClass("sorted")
// } else if (i <= colen) {
// console.log($(item).attr("id"))
// $(".main .col" + (i + 2)).append(item)
// $("#data-" + i).addClass("sorted")
// } else {
//resort item
insertToMinColumn(colen, item);
}
// }
} else {
//缩小的
// console.log(" min to " + colen)
for (var i = 1; i <= $(".main .small").length; i++) {
var item = $("#data-" + i);
insertToMinColumn(colen, item);
}
for (var i = colen + 1; i <= orilen + 2; i++) {
$(".main .col" + i).remove();
}
}
calcCircleSize(colen);
ticking = false;
}
function requestTick () {
if (!ticking) {
requestAnimationFrame(function () {
update();
});
ticking = true;
}
}
function initNewsItem () {
var w = calcW();
var colen = caclCol(w);
appendCol(colen)
$(".main .bigitem").append($("#news .news-item.pic")[0]);
$(".main .bigitem").find(".news-item").addClass("big");
$(".main .bigitem .big").attr("id", "big")
var small = w / colen;
var smallcircle = small - 24;
$("#news .news-item .news-info .circle").css({ "width": smallcircle + "px", "height": smallcircle + "px" });
$("#news .pic .news-img").css({ "width": smallcircle + "px", "height": smallcircle + "px" });
var big = 2 * small + 12;
var lw = 100 * big / $(window).width();
$(".main .left").css("width", lw + "%");
$(".main .right").css("width", (100 - lw) + "%");
var bigcircle = big - 24 - 12;
$(".main .left .big .news-info .circle").css({ "width": bigcircle + "px", "height": bigcircle + "px" });
$(".main .left .big .news-img").css({ "width": bigcircle + "px", "height": bigcircle + "px" });
var rcol = "calc((100% - 12px) /" + (colen - 2) + ")";
$(".main .right>div").css("width", rcol)
var last = "calc((100% - 12px) /" + (colen - 2) + " + 12px)";
$(".main .right>div:last-child").css("width", last);
var t1 = (colen - 2) * 2; //右侧先放两行
$("#news .news-item").each(function (index, item) {
var num = index + 1;
var colnum = 0;
if (num <= t1) {
colnum = num % (colen - 2);
if (colnum == 0) colnum = colen - 2;
colnum += 2;
} else {
colnum = minitem(colen);
}
$(".col" + colnum).append(item);
$(item).addClass("small");
$(item).attr("id", "data-" + num)
});
setLine();
newsitemEvent();
}
function initHomeBottomNav () {
var len = $(".bottom-nav>li").length;
$("#home-bottom .bottom-nav>li").css("width", "calc((100% - 24px) * " + 1 / len);
$("#home-bottom .bottom-nav>li:first-child, #home-bottom .bottom-nav>li:last-child").css("width", "calc((100% - 24px) * " + 1 / len + " + var(--padw))");
}
function calcCircleSize (colen) {
var smallcircle = ($(window).width() - 24) / colen;
var small = ($(window).width() - 24) / colen;
$(".main .right>div").css("width", small + "px");
$(".main .right>div:last-child").css("width", (small + 12) + "px");
var big = 2 * small + 12;
var smallcircle = small - 24;
$(".main .small.pic .news-info .circle").css({ "width": smallcircle + "px", "height": smallcircle + "px" });
$(".main .pic .news-img").css({ "width": smallcircle + "px", "height": smallcircle + "px" });
var lw = 100 * big / $(window).width();
$(".main .left").css("width", lw + "%");
$(".main .right").css("width", (100 - lw) + "%");
var bigcircle = big - 24 - 12;
$(".main .big .news-info .circle").css({ "width": bigcircle + "px", "height": bigcircle + "px" });
$(".main .big .news-img").css({ "width": bigcircle + "px", "height": bigcircle + "px" });
var rcol = "calc((100% - 12px) /" + (colen - 2) + ")";
$(".main .right>div").css("width", rcol)
var last = "calc((100% - 12px) /" + (colen - 2) + " + 12px)";
$(".main .right>div:last-child").css("width", last);
$(".news-item").each(function (index, obj) {
var that = this;
var h = $(this).height();
var w = $(this).width();
if ($(this).hasClass("pic")) {
var dataid = $(this).attr("id");
var img = new Image();
var imgsrc = $(this).find(".news-img .circle").attr("data-image");
img.src = $(this).find(".news-img .circle").attr("data-image");
img.id = dataid;
$(this).find(".news-img").find(".circle").css("background-image", "url(" + imgsrc + ")");
img.h = h;
img.w = w;
img.onload = function () {
var d1 = img.height / img.width;
var d2 = img.h / img.w;
if (img.height > img.width) {
if (d2 > d1) {
$("#" + img.id).find(".news-img").find(".circle").css("background-size", img.width * img.h / img.height + "px " + img.h + "px");
} else {
$("#" + img.id).find(".news-img").find(".circle").css("background-size", img.w + "px " + img.w * img.height / img.width + "px");
}
}
else {
$("#" + img.id).find(".news-img").find(".circle").css("background-size", img.width * img.h / img.height + "px " + img.h + "px");
}
}
}
});
setLine();
}
function minitem (colen) {
var min = 1;
var bigh = $(".main .big").height();
var minh = $(".main .col1").height() + bigh;
for (var i = 2; i <= colen; i++) {
var ih = $(".main .col" + i).height();
if (i <= 2) ih += bigh;
if (minh > ih) {
minh = ih;
min = i;
}
}
return min;
}
function insertToMinColumn (colen, item) {
var min = 1;
var minh = caclColHeight(1);
//console.log("1 " + minh)
for (var i = 2; i <= colen; i++) {
var ih = caclColHeight(i);
// console.log(i + ' ' + ih)
if (ih < minh) {
minh = ih;
min = i;
}
}
// console.log($(item).attr("id") + " " + min)
if (minh > 0) {
if ($(".main .col" + min + " .sorted").length > 0)
$(".main .col" + min + " .sorted").last().after(item);
else
$(".main .col" + min).append(item);
}
else if (minh == 0) {
if ($('.main .col' + min).children().length > 0)
$('.main .col' + min).children().eq(0).after(item);
else
$(".main .col" + min).append(item);
}
$(item).addClass("sorted");
function caclColHeight (colNum) {
var h = 0;
$(".main .col" + colNum + " .sorted").each(function () {
h += $(this).height();
});
if (colNum <= 2) h += $(".main .big").height();
return h;
}
}
function updateHeaderScale () {
scale = $(window).width() / 1920;
maxh = logoh * scale;
$(".root").css("top", maxh + "px")
// $(".nav>ul>li").css("width", 189 * scale + "px")
// $(".nav>ul>li>div.submenu").css(189 * scale * 2 + "px")
}
function loadsvg () {
for (var i = 2; i <= max; i++) {
var url = logopath + "R255_G-" + pad(i, 2) + ".svg";
var image = $('
');
image.attr("id", "g-" + i);
image.attr("src", url);
$("#g").append(image);
}
}
function setLine () {
$(".newscol").removeClass("ashow").removeClass("bshow");
for (var i = 1; i < $(".newscol").length + 1; i++) {
var next = i + 1;
if ($(".col" + i).height() >= $(".col" + next).height()) {
$(".col" + i).addClass("ashow");
} else {
$(".col" + next).addClass("bshow")
}
}
if ($(".bigitem").height() + $(".col2").height() > $(".col3").height()) {
$(".bigitem").addClass("show")
$('.col2').addClass("ashow")
$(".col3").removeClass("bshow")
} else {
$(".col3").addClass("bshow")
$(".bigitem").removeClass("show")
$('.col2').removeClass("ashow")
}
}