function bannerppt(jso) { var pptpic = $(jso.pic); var len = pptpic.find("ul li").length; var img = pptpic.find("ul li img"); var wid = 100; var index = 0; var picTimer; // 添加小按钮 if(len > 1){ var btn = "
"; for (var i = 0; i < len; i++) { var src = $(img[i]).attr('src'); btn += ''; } btn += "
"; pptpic.append(btn); } // 小按钮点击事件 pptpic.find(".btn span").addClass("atm5").mouseover(function () { index = pptpic.find(".btn span").index(this); showPics(index); }).eq(0).trigger("mouseover"); // 给ul与li的宽度赋值 pptpic.find("ul").css({"width": wid * len + '%'}).find("li").css({"width": wid / len + '%'}); // 鼠标滑上焦点图事件 pptpic.hover(function () { clearInterval(picTimer); },function(){ picTimer=setInterval(function(){ showPics(index); index++; if(index==len){index=0;} }, jso.time); }).trigger("mouseleave"); // 图片切换 function showPics(index) { var nowLeft = -index * pptpic.innerWidth(); // ul每次滑动距离 pptpic.find("ul").stop(true, false).animate({ "left": nowLeft }, 500); // ul切换动作及持续时间 pptpic.find("ul li").removeClass("active").stop(true, false).eq(index).stop(true, false).addClass("active"); pptpic.find(".btn span").removeClass("on").stop(true, false).eq(index).stop(true, false).addClass("on"); // 小按钮状态 } }