fn imagesSlider function opts var opts extend touch_speed step 50 px d

 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
$.fn.imagesSlider = function (opts) {
var opts = $.extend({
touch_speed: 1,
step: 50, // px
duration: 700
}, opts);
var el = this;
var $wrap = el.find('.photos_slider-wrap'),
$prev = el.find('.photos_slider-prev'),
$next = el.find('.photos_slider-next'),
is_overflow, last_x, last_scroll;
if (!$wrap.length) {
el.children().wrapAll('<div class="photos_slider-wrap"></div>');
$prev = $('<div class="photos_slider-prev"><div></div></div>');
$next = $('<div class="photos_slider-next"><div></div></div>');
el.addClass('photos_slider').append($prev).append($next);
$wrap = el.find('.photos_slider-wrap');
function move(pos, scroll) {
var new_scroll = Math.floor(Math.max(0, (typeof scroll == "number" ? scroll : $wrap.scrollLeft()) + pos));
$wrap.scrollLeft(new_scroll);
$prev.toggle($wrap.scrollLeft() > 0);
if (pos < 0) {
$next.show();
} else {
$next.toggle(new_scroll == Math.floor($wrap.scrollLeft()));
}
}
$prev.on('click', function (e) {
e.preventDefault();
move(-opts.step);
$next.show();
});
$next.on('click', function (e) {
e.preventDefault();
move(opts.step);
});
$wrap.on('touchstart', function (e) {
var touches = e.originalEvent.touches;
if (touches.length > 1)
return;
last_x = touches[0].clientX,
last_scroll = $wrap.scrollLeft();
});
$wrap.on('touchmove', function (e) {
e.stopPropagation();
var touches = e.originalEvent.touches;
if (touches.length > 1)
return;
var x = touches[0].clientX;
move((last_x - x) * opts.touch_speed, last_scroll);
return false;
});
}
var last = $wrap.children().addClass('photos_slider-item').last();
is_overflow = (($wrap.offset().left + $wrap.innerWidth()) <= (last.offset().left + last.outerWidth()));
$next.toggle(is_overflow);
$prev.hide();
return this;
};