var i = 0; //图片标识 var img_num = $(".img_ul").children("li").length; //图片个数 var num1=4 var num2=2 var m=$(".img_hd ul li").outerwidth(true)*num1 $(".img_hd").width(m) $(".img_hd ul li:first").addclass("on") $(function() { $(".img_hd ul").css("width", ($(".img_hd ul li").outerwidth(true)) * img_num); //设置ul的长度 if (!window.xmlhttprequest) { //对ie6设置a的位置 $(".change_a").css("height", $(".change_a").parent().height()); } $(".change_a").hover(function() { //箭头显示事件 $(this).children("span").show(); }, function() { $(this).children("span").hide(); }); $(".img_hd ul li").click(function() { i = $(this).index(); play(); }); $(".prev_a").click(function() { //i+=img_num; i--; //i=i%img_num; i = (i < 0 ? 0 : i); play(); clearinterval(time) }); $(".next_a").click(function() { i++; i=i%img_num; i = (i > (img_num - 1) ? (img_num - 1) : i); play(); clearinterval(time) }); //自动播放 function autoplay(){ i++; i=i%img_num; i = (i > (img_num - 1) ? (img_num - 1) : i); play(); } time=setinterval(autoplay,5000) $('.imgmove,.change_a').hover(function(){ clearinterval(time) },function(){ time=setinterval(autoplay,5000) }) //end }); function play() { //动画移动 var img = new image(); //图片预加载 img.onload = function() { img_load(img, $(".img_ul").children("li").eq(i).find("img")) }; img.src = $(".img_ul").children("li").eq(i).find("img").attr("src"); $(".img_hd ul").children("li").eq(i).addclass("on").siblings().removeclass("on"); if (img_num > num1) { //大于num1个的时候进行移动 if (i < img_num - num2) { //前3个 $(".img_hd ul").animate({ "marginleft": ( - ($(".img_hd ul li").outerwidth(true)) * (i - num2 < 0 ? 0 : (i - num2))) }); } else if (i >= img_num - num2) { //后3个 $(".img_hd ul").animate({ "marginleft": ( - ($(".img_hd ul li").outerwidth(true)) * (img_num - num1)) }); } } if (!window.xmlhttprequest) { //对ie6设置a的位置 $(".change_a").css("height", $(".change_a").parent().height()); } } function img_load() { //大图片加载设置 ( 新建的img,now_imgid当前图片) $(".img_ul").children("li").eq(i).show().siblings("li").hide(); //大小确定后进行显示 } $(".img_hd li").each(function(index, element) { $(this).find("i").html(index+1+"/"+img_num) }); $(".zoomimg2").autozoomloadimage(true, 70, 47); $(".zoomimg1").autozoomloadimage(true, 600, 400);