This repository was archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.slideshow.js
More file actions
144 lines (106 loc) · 3.47 KB
/
jquery.slideshow.js
File metadata and controls
144 lines (106 loc) · 3.47 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
(function($){
//plugin boilerplate:
//http://stefangabos.ro/jquery/jquery-plugin-boilerplate-revisited/?utm_source=javascriptweekly&utm_medium=email
$.slideshow = function(element, options) {
// plugin's default options
// this is private property and is accessible only from inside the plugin
var defaults = {
autoPlay: true,
hoverArrows: true,
continuous: false,
sliding: null,
navElem: null
},
//Convenience
plugin = this,
$element = $(element),
element = element,
$els = $element.find(".slide");
//Private functions
plugin.settings = {};
// the "constructor" method that gets called when the object is created
plugin.init = function() {
// the plugin's final properties are the merged default and user-provided options (if any)
plugin.settings = $.extend({}, defaults, options);
// code goes here
if (plugin.settings.hoverArrows) {
(function () {
var ps = $("<div id='prev-slide' class='slide-arrow' style='display:none'><</div>"),
ns = $("<div id='next-slide' class='slide-arrow' style='display:none'>></div>");
$element.append(ps).append(ns);
ps.bind("click", function () {
var li = $(".s", $element),
ind = li.index();
if (!li.prev().prev().length) {
$("#prev-slide").hide();
}
if ($element.length <= ind + 2) {
$("#next-slide").show();
}
if (ind > 0) {
li.removeClass("s");
goTo(ind);
}
});
ns.bind({
click: function () {
var li = $(".s", $element),
ind = li.index();
if ($els.length <= ind + 2) {
$("#next-slide").fadeOut(100);
}
if (li.prev().prev()) {
$("#prev-slide").fadeIn(100);
}
if (ind < $els.length) {
li.removeClass("s");
goTo(ind + 2);
}
}
});
$element.bind({
mouseenter: function () {
var current = $(".s", $element).index(),
toShow = (current > 0 && current + 1 < $els.length) ? "#prev-slide, #next-slide" :
(current + 1 < $els.length) ? "#next-slide" :
(current + 1 == $els.length) ? "#prev-slide" : "";
$(toShow).fadeIn(500);
},
mouseleave: function () {
$(".slide-arrow").fadeOut(500);
}
});
}());
}
};
var goTo = function (ind) {
var e = $element.find("li:nth-child(" + ind + ")"),
mL = e.outerWidth() * (ind-1);
e.addClass("s");
$element.animate({
marginLeft: -mL + "px"
}, 300, "swing");
};
// fire up the plugin!
// call the "constructor" method
plugin.init(plugin.settings);
}
// add the plugin to the jQuery.fn object
$.fn.slideshow = function(options) {
// iterate through the DOM elements we are attaching the plugin to
return this.each(function() {
// if plugin has not already been attached to the element
if (undefined == $(this).data('slideshow')) {
// create a new instance of the plugin
// pass the DOM element and the user-provided options as arguments
var plugin = new $.slideshow(this, options);
// in the jQuery version of the element
// store a reference to the plugin object
// you can later access the plugin and its methods and properties like
// element.data('pluginName').publicMethod(arg1, arg2, ... argn) or
// element.data('pluginName').settings.propertyName
$(this).data('slideshow', plugin);
}
});
}
})(window.jQuery);