-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.sliderFlow.js
112 lines (87 loc) · 2.6 KB
/
jquery.sliderFlow.js
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
/*
Slider flow, version 0.2
https://github.com/Kraigo/sliderFlow
Author: Kraigo
*/
(function($) {
$.fn.sliderFlow = function(options) {
// Settings
var settings = $.extend({
'container' : '.slider-container',
'navigation' : '.slider-navigation',
'slide': '.slide',
'equalHeight': true,
'speed': 300
}, options );
var $_slider = $(this);
var $_container = $(settings.container);
var $_navigation = $(settings.navigation);
var maxSlides = 5;
var slide_margin,
slide_quantity,
slide_width,
slide_indent;
$_navigation.slider({
value:100,
min: 0,
value: 0,
step: 1,
slide: function( event, ui ) {
slideTo( ui.value );
}
});
// Initilize
initializeSize()
$( window ).resize(function() { initializeSize() });
// ########
function initializeSize() {
if ($_slider.width() < 480) { maxSlides = 2; }
else if ($_slider.width()>1750) {maxSlides = 7;}
else if ($_slider.width() < 760) { maxSlides = 3; }
else {maxSlides = 5;}
slide_margin = $_slider.find(settings.slide).outerWidth(true) - $_slider.find(settings.slide).width();
slide_quantity = $_slider.find(settings.slide).length;
slide_width = Math.round( $_slider.width() / maxSlides);
slide_indent = Math.floor(maxSlides/2);
$_slider.find(settings.slide).width(slide_width - slide_margin);
$_container.width(slide_quantity*slide_width);
$_navigation.slider("option", "max", slide_quantity-1 );
$_slider.find('img').one('load', equalHeight);
equalHeight();
slideTo($_navigation.slider( "value" ));
return;
};
function equalHeight() {
if (!settings.equalHeight) return false;
var currentTallest = 0;
$_slider.find('.slide').css({'height': 'auto'});
$_slider.find('.slide').each(function(i){
if ($(this).height() > currentTallest) {
currentTallest = $(this).height();
}
});
$_slider.find('.slide').css({'height': currentTallest});
};
// ** Navigation **
$_slider.on('click', settings.slide, function() {
slideTo( $(this).index() );
})
$_slider.on('slideTo', function(event, e) {
slideTo( e );
})
$_slider.on('rebuild', function () {
initializeSize();
});
function slideTo(e) {
if (e>=0 && e<=slide_quantity ) {
$_slider.find(settings.slide+'.active-slide').removeClass('active-slide');
$_slider.find(settings.slide).eq(e).addClass('active-slide');
$_slider.stop(true, false).animate({
scrollLeft: (e-slide_indent) * (slide_width)
}, settings.speed);
$_navigation.slider("value", e);
$_slider.trigger('slidechange', e);
}
}
};
})(jQuery);