$(function(){ var n = $(".banner li").length $(".banner li").each(function(){ var _this = $(this), src = _this.attr("data-img"), img = new image(); img.src = src; //澶勭悊ff涓嬩細鑷姩璇诲彇缂撳瓨鍥剧墖 if(img.complete || img.width){ _this.attr("style","background:url("+src+") no-repeat center"); n -- ; if(n == 0){ banner(); } return; } $(img).load(function(){ _this.attr("style","background:url("+src+") no-repeat center"); n -- ; if(n == 0){ banner(); } }); }) }) function banner(){ //鍒濆鍖朾anner鏍峰紡 $(".banner").css("background","none"); var listn = $(".banner > ul > li").length; $(".banner > ul > li").eq(0).fadein(1000); var sw = 1; var size_dq = $('.home_btn_news span b').size(); $('.home_btn_news span b').append(sw); $('.home_btn_news span i').append(listn); for(i=0;i'); } $(".banner .btn").css("margin-left",-$(".btn").width()/2); $(".banner .btn span").eq(0).addclass("on"); $(".banner > ul > li").eq(0).find('.bannertxt .txt1').stop(true,true).animate({ "opacity":"1", "top": "348px" },1000) $(".banner > ul > li").eq(0).find('.bannertxt .txt2').stop(true,true).animate({ "opacity":"1", "top": "500px" },1000) //执行效果 var sw = 1; $(".banner .btn span").mouseover(function(){ sw = $(".banner .btn span").index(this); myshow(sw); }); function myshow(i){ $(".banner .btn span").eq(i).addclass("on").siblings("span").removeclass("on"); $(".banner > ul > li").eq(i).stop(true,true).fadein(1000).siblings().stop(true,true).fadeout(1000); $('.home_btn_news span b').html(sw + 1); $(".banner > ul > li").eq(i).find('.bannertxt .txt1').stop(true,true).animate({ "opacity":"1", "top": "348px" },1000) $(".banner > ul > li").eq(i).find('.bannertxt .txt2').stop(true,true).animate({ "opacity":"1", "top": "500px" },1000) $(".banner > ul > li").eq(i).siblings().find('.bannertxt .txt1').stop(true,true).animate({ "opacity":"0", "top": "280px" },10) $(".banner > ul > li").eq(i).siblings().find('.bannertxt .txt2').stop(true,true).animate({ "opacity":"0", "top": "600px" },10) } //滑入停止动画,滑出开始动画 $(".banner").hover(function(){ if(mytime){ clearinterval(mytime); } },function(){ clearinterval(mytime); mytime = setinterval(function(){ myshow(sw); sw++; if(sw==listn){sw=0;} } , 5000); }); //自动开始 var mytime = setinterval(function(){ myshow(sw); sw++; if(sw==listn){sw=0;} } , 5000); //右侧按钮 var sw = 0; $(".banner .next").on('click',function(){ if(sw == listn - 1){sw = 0;}else{sw++;} myshow(sw); }) $(".banner .prev").on('click',function(){ if(sw == 0){sw = listn - 1;}else{sw--;} myshow(sw); }) } /*$(function(){ $(".banner > ul > li").loadimage(true,$(".banner > ul > li")); })*/