-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.simpleslider.js
60 lines (52 loc) · 1.47 KB
/
jquery.simpleslider.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
/*!
* Simple Slider jQuery plugin
*
* Copyright (c) 2011 Florian Plank (http://www.polarblau.com/)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* USAGE:
*
* $('.simpleslider').simpleslider({
* "controls" : $('.controls'), // selector or jquery object
* "content" : '.content', // selector or jquery object
* "transitionDuration" : 500 // duration in ms
* });
*
*/
(function($) {
$.fn.simpleslider = function(options) {
// defaults
var settings = $.merge({
"controls": '.controls',
"content": '.content',
"transitionDuration" : 500
}, options || {});
return $(this).each(function(i, e) {
var $e = $(e),
$controls = $e.find('li', settings.controls),
$content = $e.find(settings.content),
sizes = [],
contentWidth = 0;
// determine sizes of slides
$content.find('li').map(function(j, li) {
var liWidth = $(li).width();
contentWidth += liWidth;
sizes.push(liWidth);
})
$content.css('width', contentWidth + 'px');
$controls.click(function() {
// determine offset
var controlIndex = $(this).index(),
offset = (function(s) {
var w = 0; $.each(s, function(k, e) { w += e; }); return w;
})(sizes.slice(0, controlIndex));
// slide content to correct position
$content.animate({
'left': (offset * -1) + 'px'
}, settings.transitionDuration);
return false;
});
});
};
})(jQuery);