jquery.slides.js
4.76 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
(function ($) {
$.fn.bxCarousel = function (options) {
var defaults = {move:4, display_num:4, speed:500, margin:0, auto:false, auto_interval:2000, auto_dir:'next', auto_hover:false, next_text:'next', next_image:'', prev_text:'prev', prev_image:'', controls:true};
var options = $.extend(defaults, options);
return this.each(function () {
var $this = $(this);
var li = $this.find('li');
var first = 0;
var fe = 0;
var last = options.display_num - 1;
var le = options.display_num - 1;
var is_working = false;
var j = '';
var clicked = false;
if(li.length < options.display_num)
{
return false;
}
li.css({'float':'left', 'listStyle':'none', 'marginRight':options.margin});
var ow = li.outerWidth(true);
wrap_width = (ow * options.display_num) - options.margin;
var seg = ow * options.move;
$this.wrap('<div class="bx_container"></div>').width(999999);
$this.parent('.bx_container').wrap('<div class="bx_wrap"></div>').css({'position':'relative', 'width':wrap_width, 'overflow':'hidden'});
var w = li.slice(0, options.display_num).clone();
var last_appended = (options.display_num + options.move) - 1;
$this.empty().append(w);
get_p();
get_a();
$this.css({'position':'relative', 'left':-(seg)});
$('.'+options.next_dir).click(function () {
slide_next();
clearInterval(j);
clicked = true;
return false;
});
$('.'+options.pre_dir).click(function () {
slide_prev();
clearInterval(j);
clicked = true;
return false;
});
function slide_next() {
if (!is_working) {
is_working = true;
set_pos('next');
$this.animate({left:'-=' + seg}, options.speed, function () {
$this.find('li').slice(0, options.move).remove();
$this.css('left', -(seg));
get_a();
is_working = false;
});
}
}
function slide_prev() {
if (!is_working) {
is_working = true;
set_pos('prev');
$this.animate({left:'+=' + seg}, options.speed, function () {
$this.find('li').slice(-options.move).remove();
$this.css('left', -(seg));
get_p();
is_working = false;
});
}
}
function get_a() {
var str = new Array();
var lix = li.clone();
le = last;
for (i = 0; i < options.move; i++) {
le++
if (lix[le] != undefined) {
str[i] = $(lix[le]);
} else {
le = 0;
str[i] = $(lix[le]);
}
}
$.each(str, function (index) {
$this.append(str[index][0]);
});
}
function get_p() {
var str = new Array();
var lix = li.clone();
fe = first;
for (i = 0; i < options.move; i++) {
fe--
if (lix[fe] != undefined) {
str[i] = $(lix[fe]);
} else {
fe = li.length - 1;
str[i] = $(lix[fe]);
}
}
$.each(str, function (index) {
$this.prepend(str[index][0]);
});
}
function set_pos(dir) {
if (dir == 'next') {
first += options.move;
if (first >= li.length) {
first = first % li.length;
}
last += options.move;
if (last >= li.length) {
last = last % li.length;
}
} else if (dir == 'prev') {
first -= options.move;
if (first < 0) {
first = li.length + first;
}
last -= options.move;
if (last < 0) {
last = li.length + last;
}
}
}
});
}
})(jQuery);