Javascript Web Slider 焦点图示例源码_javascript技巧
程序员文章站
2022-04-27 21:55:12
...
HTML代码:
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
});
复制代码 代码如下:
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
});
上一篇: C#编程如何获取电脑硬件信息的方法?
下一篇: (四)概率
推荐阅读
-
原生JavaScript实现精美的淘宝轮播图效果示例【附demo源码下载】
-
原生JavaScript实现精美的淘宝轮播图效果示例【附demo源码下载】
-
js 上下左右键控制焦点(示例代码)_javascript技巧
-
js 上下左右键控制焦点(示例代码)_javascript技巧
-
js设置文本框中焦点位置在最后的示例代码(简单实用)_javascript技巧
-
原生javascript图片自动或手动切换示例附演示源码_javascript技巧
-
js设置文本框中焦点位置在最后的示例代码(简单实用)_javascript技巧
-
基于Flowplayer打造一款免费的WEB视频播放器附源码_javascript技巧
-
文本框(input)获取焦点(onfocus)时样式改变的示例代码_javascript技巧
-
基于Flowplayer打造一款免费的WEB视频播放器附源码_javascript技巧