jslider.js
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(function($){
$.fn.Slider = function(config){
var defaults = {
speed:'slow',
easing:'swing',
stay:5000
};
var config = $.extend(defaults, config);
return this.each(function(){
var slider = $(this),
slider_w = slider.width(),
item = slider.find('> div'),
total = item.children().length,
current=1;
slider.css({position: "relative", margin: "0 auto",overflow: "hidden"});
slider.find("div").css({position: 'absolute',width: '19999px',display: 'block'});
item.children().eq(0).clone().appendTo(item);
var tem = '<ul class="dot-nav">';
for (var i = 1; i <= total; i++) {
tem+='<li><a>'+i+'</a></li>';
}
slider.append(tem+'</ul>');
slider.find(".dot-nav > li").removeClass('current').eq(0).addClass('current');
//$(".dot-nav >li > a",slider).each(function(i){
slider.find(".dot-nav >li > a").each(function(i){
$(this).on("click", function(){
run(i);
});
$(this).on("mouseover",function(){clearInterval(si);});
$(this).on("mouseout",function(){
si = setInterval(function(){
run();}, config.stay);});
});
var run = function (index){
if(index!=undefined) current=index;
item.animate({left: -1 * slider_w * current},config.speed,config.easing,function(){
current++;
if(current>total){
current=1;
item.css({left:0});
}
slider.find(".dot-nav > li").removeClass('current').eq(current-1).addClass('current');
});
}
//run(1);
var si = setInterval(function(){
run();
}, config.stay);
});
}
})(jQuery);