欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

Javascript Web Slider 焦点图示例源码_javascript技巧

程序员文章站 2022-04-01 10:56:51
...
HTML代码:
复制代码 代码如下:










  • Javascript Web Slider 焦点图示例源码_javascript技巧

  • Javascript Web Slider 焦点图示例源码_javascript技巧

  • Javascript Web Slider 焦点图示例源码_javascript技巧

  • Javascript Web Slider 焦点图示例源码_javascript技巧

  • Javascript Web Slider 焦点图示例源码_javascript技巧















Javasscript 代码:
复制代码 代码如下:

function Sliderfocus(options){
this.focus = options.focus;
this.slider = options.slider;
this.btns = options.btns;
this.width = options.width;
this.speed = options.speed || 800;
this.curIndex = options.curIndex || 0;
this.size = this.btns.size();
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({
focus:$(".slider-focus"),
slider:$(".slider-focus .slider"),
btns:$(".btns li"),
width:670
});
相关标签: Slider 焦点图