HTML程式碼:
;
;
標題>
*{padding:0;margin:0}
ul{list-style:none}
.slider-focus{width:670px;height:240px;overflow:hidden;position:relative;margin: 100px 自動}
.slider-focus .slider{width:3500px;位置:絕對;左:slider-focus .slider{width:3500px;位置:絕對;左:0px;上圖:0px;高度:240px}
.slider-focus .slider li{float:left;}
.slider-focus .btns{位置:絕對;右:0px;底部:5px}
. slider-focus .btns li{寬度:18px;高度:18px;浮動:左;背景:#fff;右邊距:5px;遊標:指針}
.slider-focus .btns li.cur{背景:#f60 }
;
頭>
身體>
JavaScript 程式碼:
程式碼如下:
function Sliderfocus(options){ this.slider = options.slider;
this.btns = options.btns;
this.width = options.width;
this.speed = options.speed =peed | | 800;
this.curIndex = options.curIndex || 0;
this.size = this.btns.size();
this.init();
this.timeout = null;
this.init();
this.timeout = null;
this.stopTemp = 1 ;
}
Sliderfocus.prototype = {
init:function(){
this.auto();
this.bind() ;
},
play:function(){
this.slider.stop().animate({
left:-this.curIndex * this.width
},this.speed ) ;
},
auto:function(){
var that = this;
this.timeout = setTimeout(function(){
if(that.stopTemp == 0){
return;
}else{
that.next();
that .auto();
}
},4000);
},
prev :function(){
this.curIndex = --this.curIndexthis.play();
},
next:function (){
this.curIndex = this.curIndex>this.size-1? 0 : this.curIndex;
console.log(this.curIndex)
this.play();
} ,
stop:function(){
this.stopTemp = 0;
},
bind:function(){
var that = this;
this.focus.bind( "mouseover",function(){
that.stop();
}).bind("mouseout",function(){
that.stopTemp = 1 ;
//that.auto ();
});
this.letsgo();
},
letsgo:function(){
var that = this;
this.btns.bind(" click",function(){
var index = $(this).index();
that.curIndex = index;
that.play();
});
}
};
new Sliderfocus({
焦點:$(".slider-focus"),
slider:$(".slider-focus .slider"),
btns:$(" .btns li"),
寬度:670
});