$(function () { var win_width = 0; var win_height = 0; var bannerInd = 0; var bannerInv = null; var newsInd = 0; var newsInv = null; init(); main(); $(".nav li").mouseover(function () { $(this).find(".subNav").stop(false, false).slideDown(300); }).mouseleave(function () { $(this).find(".subNav").stop(false, false).slideUp(300); }); function init() { win_width = $(window).width(); win_height = $(window).height(); setImgMax($(".bannerBox img"), 1485, 750); } function main() { createBtns(); changeBanner(); createNewsBtns(); changeNews(); $(".weixin").mouseover(function () { $(this).find(".erweima").stop(false, false).animate({ bottom: 20, opacity: "show" }); }).mouseleave(function () { $(this).find(".erweima").stop(false, false).animate({ bottom: 10, opacity: "hide" }); }); } function autoChangeBanner() { clearTimeout(bannerInv); bannerInv = setTimeout(function () { if (bannerInd >= $(".bannerBox img").size() - 1) { bannerInd = 0; } else { bannerInd++; } changeBanner(); }, 5000); } function autoChangeNews() { clearTimeout(newsInv); newsInv = setTimeout(function () { if (newsInd >= $(".newsBox li").size() - 1) { newsInd = 0; } else { newsInd++; } changeNews(); }, 4000); } function changeBanner() { clearTimeout(bannerInv); $(".bannerBox img").stop(false, false).fadeOut() .eq(bannerInd).stop(false, false).fadeIn(); $(".bannerText img").stop(false, false).animate({ marginBottom: 80, opacity: "hide" }, 600) .eq(bannerInd).stop(false, false).animate({ marginBottom: 0, opacity: "show" }, 600); $(".btns span").removeClass("cur").eq(bannerInd).addClass("cur"); autoChangeBanner(); } function createBtns() { var str = ''; for (var i = 0; i < $(".bannerBox img").size() ; i++) { str += ''; } $(".btns").html(str).find("span").mouseover(function () { if ($(this).hasClass("cur")) { return; } bannerInd = $(this).index(); changeBanner(); }).eq(0).addClass("cur"); } function changeNews() { clearTimeout(newsInv); var aLi = $(".newsBox li"); aLi.stop(false, false).animate({ left: -80, opacity: "hide" }); aLi.eq(newsInd).stop(false, false).css({ left: 80 }).animate({ left: 0, opacity: "show" }); $(".newsBtns span").removeClass("cur").eq(newsInd).addClass("cur"); autoChangeNews(); } function createNewsBtns() { var str = ''; for (var i = 0; i < $(".newsBox li").size() ; i++) { str += ''; } $(".newsBtns").html(str).find("span").mouseover(function () { if ($(this).hasClass("cur")) { return; } newsInd = $(this).index(); changeNews(); }).eq(0).addClass("cur"); } function setImgMax(img, imgW, imgH, tW, tH) { //设置图片宽高比例 var tWidth = tW || win_width; var tHeight = tH || win_height; var coe = imgH / imgW; var coe2 = tHeight / tWidth; if (coe < coe2) { var imgWidth = tHeight / coe; img.css({ height: tHeight, width: imgWidth, left: -(imgWidth - tWidth) / 2, top: 0 }); } else { var imgHeight = tWidth * coe; img.css({ height: imgHeight, width: tWidth, left: 0, top: -(imgHeight - tHeight) / 2 }); } } $(window).resize(function () { init(); }); });