$(document).ready(function(e) {
var lis=$("#bannerb ul li");
var len=lis.length;
var index = 0;
var pictimer;
var scrolltime=3500; //图片切换时间
pictimer=setinterval(scrollfun,scrolltime); //加载后自动播放
//鼠标上浮后停止滚动并显示左右箭头,离开后自动播放
$("#bannerb").on({
"mouseover":function(){
clearinterval(pictimer);
$("#bannerb .bannebtl").css("display","block");
$("#bannerb .bannebtr").css("display","block");
},
"mouseleave":function() {
pictimer = setinterval(scrollfun,scrolltime);
$("#bannerb .bannebtl").css("display","none");
$("#bannerb .bannebtr").css("display","none");
},
"contextmenu":function(){
return false;
}
});
//滚动函数
function scrollfun(){
index++;
if(index == len) {index = 0;}
showpics(index); //图片滚动与语句顺序有关!
}
//以下代码添加数字按钮,还有上一页、下一页两个按钮
if(len>1){
var btn="
"
btn += "";
for(var i=0;i";
}
btn += "
";
$("#bannerb").append(btn);
$("#bannerb #banneindex span").first().css("background","red"); //加载时第一张问为选中状态
//数字按钮鼠标划上动作
$("#bannerb #banneindex span").mouseover(function(){
showpics($(this).index());
});
//切换到前一张
$("#bannerb .bannebtl").click(function(){
index--;
if(index == -1) {index = len - 1;}
showpics(index);
});
//切换到后一张
$("#bannerb .bannebtr").click(function(){
index++;
if(index == len) {index = 0;}
showpics(index);
});
}
//图片切换函数
function showpics(index){
$("#bannerb ul li:eq("+index+")").stop(true,true).show();
$("#bannerb ul li:gt("+index+")").stop(true,true).hide();
$("#bannerb ul li:lt("+index+")").stop(true,true).hide();
if(len>1){
$("#bannerb span:eq("+index+")").css("background","red");
$("#bannerb span:gt("+index+")").css("background","#999");
$("#bannerb span:lt("+index+")").css("background","#999");
}
}
});