锘?.fn.jqslider = function() {
var fun = function(parentObj){
var picTotal = parentObj.find('.list-box li').length; //鎬诲叡鍑犲紶
var currentIndex = 0; // 褰撳墠瑕佹樉绀虹殑绱㈠紩
var toDisplayPicNumber = 1; // 瀹氭椂鍣ㄤ笅涓€娆℃墽琛岀敤鍒扮殑绱㈠紩
var timer = null; // 瀹氭椂鍣ㄥ璞
var hideIndex = 0; // 瑕侀殣钘忕殑绱㈠紩
var iTime = 6000; // 闂撮殧鏃堕棿
//鎻掑叆HTML浠g爜
var speedHtml = '
';
for(var i=0; i
';
}
speedHtml += ' ';
$(speedHtml).appendTo(parentObj); //鎻掑叆杩涘害鎸夐挳
$('').appendTo(parentObj); //鎻掑叆宸﹀彸鎸夐挳
parentObj.find('.list-box li').eq(0).css({'opacity':1,'z-index':2});
parentObj.find('.speed-btn a').eq(0).addClass('selected');
//绉讳笂绉讳笅鏄剧ず闅愯棌
parentObj.hover(function(){
clearTimeout(timer);
parentObj.find('.prev-btn').show();
parentObj.find('.next-btn').show();
},function(){
parentObj.find('.prev-btn').hide();
parentObj.find('.next-btn').hide();
timer = setTimeout(PicNumClick, iTime);
//绂诲紑浠庢柊璧嬪€
toDisplayPicNumber = (currentIndex + 1 == picTotal ? 0 : currentIndex + 1);
});
//涓嬩竴涓
parentObj.find('.next-btn').click(function(){
currentIndex = (currentIndex + 1 == picTotal ? 0 : currentIndex + 1);
DisplayPic();
});
//涓婁竴涓
parentObj.find('.prev-btn').click(function(){
currentIndex = (currentIndex - 1 < 0 ? picTotal-1 : currentIndex -1);
DisplayPic();
});
//涓棿鎸夐挳
parentObj.find('.speed-btn a').click(function(){
currentIndex = $(this).index();
DisplayPic();
});
//鍥剧墖鍒囨崲鏁堟灉
function DisplayPic() {
clearTimeout(timer);
if(currentIndex == hideIndex){return;}
parentObj.find('.list-box li').eq(currentIndex).css({'opacity':1,'z-index':2});
parentObj.find('.list-box li').eq(hideIndex).css({'z-index':5}).stop(true,true).animate({'opacity':0}, 300 , function(){
hideIndex = currentIndex;
$(this).css({'z-index':1});
});
parentObj.find('.speed-btn a').eq(currentIndex).addClass('selected').siblings().removeClass('selected');
}
//寰幆璋冪敤鑷韩
function PicNumClick() {
parentObj.find(".speed-btn a").eq(toDisplayPicNumber).trigger("click");
toDisplayPicNumber = (toDisplayPicNumber + 1) % picTotal;
timer = setTimeout(PicNumClick,iTime);
}
setTimeout(PicNumClick, iTime);
};
return $(this).each(function() {
fun($(this));
});
}