(function(){ //newsadver滚动轮播类 function newsadver(args){ for(var i in args){ this[i] = args[i]; } this.speed = args.speed ? args.speed : 3000; //间隔时间默认3秒 this.stime = args.stime ? args.stime : 500; //渐进时间,默认1秒 this.load(); this.start(); } newsadver.prototype = { load : function(){ var _this = this; this.num = 0; //计时器 this.mnum = this.num+1; //轮播计时 this.snum = 0; //滚动时的hover位置 this.len = this.divs.length; //所有div设置absolute并排好index this.divs.each(function(num){ var z_index = 500-num; $(this).css({ "position" : "absolute", "left" : 0, "top" : 0, "z-index" : z_index, "display" : "none" }) }); $(this.divs[0]).show(); //所有div设置absolute并排好index //btn.parent()克隆一份放在下面 var btnclone = this.btns.parent().clone(); $("li",btnclone).removeclass("hover"); btnclone.appendto(this.btns.parent().parent()); /* this.btns.each(function(num){ $(this).mouseover(function(){ _this.show(num); _this.stop(); }).mouseout(function(){ _this.start(); }); }); */ }, show :function(num){ if(num == this.num) return; //同一个返回 var _this = this; this.flag = false; //关闭控制开关 this.btns.each(function(i){ if(i == num){ $(this).addclass("hover"); }else{ $(this).removeclass("hover"); } }); $(this.divs[this.num]).fadeout(this.stime); //旧的淡出 $(this.divs[num]).fadein(_this.stime); //新的淡入 _this.num = num; _this.mnum = num+1; }, start : function(){ var _this = this; var scrollpar = this.btns.parent().parent(); var scrollh = this.btns.height()+parseint(this.btns.css("margin-bottom")); this.interval = setinterval(function(){ if(_this.mnum >= _this.len){ _this.mnum = 0; } if(scrollpar.scrolltop() >= _this.btns.parent().height()){ scrollpar.scrolltop(0); _this.snum = 0; } scrollpar.animate({ scrolltop : scrollpar.scrolltop()+scrollh }); _this.show(_this.mnum); _this.snum++; $("li",scrollpar).removeclass("hover"); $($("li",scrollpar)[_this.snum]).addclass("hover"); },this.speed); }, stop : function(){ clearinterval(this.interval); } }; window.newsadver = newsadver; //newsadver滚动轮播类 })(); $(function(){ //index_banner轮播效果 $(".index_banner .big li").each(function(){ $(this).css("background-image","url("+$(this).attr("bg")+")"); }); new fadeadver({ btns : $(".index_banner .btns span"), divs : $(".index_banner .big li"), speed :10000 }); //news_adver轮播开始 new newsadver({ btns : $(".news_adver .btn li"), divs : $(".news_adver .big li") }); //active_adver鼠标hover效果 /*旧的 new fadeadver({ btns : $(".active_adver .btn span"), divs : $(".active_adver .adv"), speed :5000 }); */ var active_adv0 = $(".active_adver .adv_0"); var active_adv1 = $(".active_adver .adv_1"); var active_adv2 = $(".active_adver .adv_2"); var adv0_time; var adv1_time; var adv2_time; var count = 0; var lunbo = setinterval(function(){ if (count == 3) { count = 0; } $(".adv_" + count).fadein(1000); $(".adv_" + count).siblings().fadeout(1000); count++; }, 3000); /*function showadv1(){ adv1_time = settimeout(function(){ active_adv1.fadeout(1000); active_adv2.fadein(1000,function(){ adv2_time = settimeout(function(){ active_adv2.fadeout(1000); active_adv1.fadein(1000,function(){ showadv1(); }); },3000); }); },6000); } adv1_time = settimeout(function(){ active_adv1.fadeout(1000); active_adv2.fadein(1000,function(){ adv2_time = settimeout(function(){ active_adv2.fadeout(1000); active_adv1.fadein(1000,function(){ showadv1(); }); },3000); }); },6000);*/ $(".active_adver").hover(function(){ cleartimeout(adv1_time); cleartimeout(adv2_time); clearinterval(lunbo); },function(){ /*adv1_time = settimeout(function(){ active_adv1.fadeout(1000); active_adv2.fadein(1000,function(){ adv2_time = settimeout(function(){ active_adv2.fadeout(1000); active_adv1.fadein(1000,function(){ showadv1(); }); },3000); }); },1000);*/ lunbo = setinterval(function(){ if (count == 3) { count = 0; } $(".adv_" + count).fadein(1000); $(".adv_" + count).siblings().fadeout(1000); count++; }, 3000); }); $(".active_adver .adv_1 a").each(function(){ var h = $(this).height()+46; var w= $(this).width(); $("span",this).height(h); $("span",this).width(w); }); $(".active_adver .adv_1 a").hover(function(){ $(".active_adver .adv_1 a span").show(); $("span",this).hide(); },function(){ $(".active_adver .adv_1 a span").hide(); }); //active_aside的hover效果 var aside_adver_num = 0; var aside_adver_time; var aside_ads = $(".aside_adver .ad"); function runasinter(){ aside_adver_time = setinterval(function(){ var tnum; $(aside_ads[aside_adver_num]).animate({"width":74},"fast",function(){ $(this).removeclass("hover"); }); if(aside_adver_num == 2){ tnum = 0; }else{ tnum = aside_adver_num + 1; } $(aside_ads[tnum]).animate({"width" : 170},"fast",function(){ $(this).addclass("hover"); }); aside_adver_num++; if(aside_adver_num >= 3){ aside_adver_num = 0; } },5000); } function clearasinter(){ clearinterval(aside_adver_time); } //runasinter(); aside_ads.each(function(num){ $(this).mouseover(function(){ var _this = this; //clearasinter(); if(num == aside_adver_num){ return false; } $(aside_ads[aside_adver_num]).animate({"width":74},"fast",function(){ $(this).removeclass("hover"); $("span",this).show(); }); $("span",this).fadeout("fast"); $(this).animate({"width" : 170},"fast",function(){ $(_this).addclass("hover"); }); aside_adver_num = num; }); $(this).mouseout(function(){ //runasinter(); }); }); //active_data轮播 new fadeadver({ btns : $(".active_data .change span"), divs : $(".active_data .con"), speed :5000 }); //welcome广告开始 showwelcome(); });