Skip to content

Commit 37795dc

Browse files
committed
Updating event triggers and readme file.
1 parent 7230e2f commit 37795dc

File tree

2 files changed

+82
-25
lines changed

2 files changed

+82
-25
lines changed

README.md

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,39 @@ JQuery plugin that can create a background slideshow. This plugin works differe
2727
</body>
2828
```
2929

30-
Complete option usage:
30+
Complete option usage with JavaScript:
3131

3232
```javascript
33-
<script type="text/javascript">
34-
$(function () {
35-
$(".bg").bgSlideShow({
36-
current : 0,
37-
images : ["../gfx/first.png", "../gfx/second.png"],
38-
transitionDelay : 5000, // 5 seconds
39-
transitionSpeed : 3000, // 3 seconds
40-
transitionEffect : 'fade-in',
41-
randomize : false,
42-
initialBackground : 'random',
43-
debug : true,
44-
eventHandlers : {
45-
beforeInit: myBeforeInitFunc,
46-
afterInit: myAfterInitFunc,
47-
beforeChange : myBeforeChangeFunc,
48-
afterChange : myAfterChangeFunc
49-
}
50-
});
33+
$(function () {
34+
$(".bg").bgSlideShow({
35+
current : 0,
36+
images : ["../gfx/first.png", "../gfx/second.png"],
37+
transitionDelay : 5000, // 5 seconds
38+
transitionSpeed : 3000, // 3 seconds
39+
transitionEffect : 'fade-in',
40+
randomize : false,
41+
initialBackground : 'random',
42+
debug : true,
43+
eventHandlers : {
44+
beforeInit: myBeforeInitFunc,
45+
afterInit: myAfterInitFunc,
46+
beforeChange : myBeforeChangeFunc,
47+
afterChange : myAfterChangeFunc
48+
}
5149
});
52-
</script>
50+
});
51+
```
52+
53+
Complete option usage with data attributes:
54+
55+
```html
56+
<div class='bg' data-current="0"
57+
data-images="../gfx/first.png,../gfx/second.png"
58+
data-transitionDelay="5000" data-transitionSpeed="3000"
59+
data-transitionEffect="fade-in" data-randomize="true"
60+
data-initialBackground="2" data-debug="false">
61+
HTML content for the div
62+
</div>
5363
```
5464

5565
## Examples
@@ -78,10 +88,51 @@ $(function () {
7888

7989
<div class='bg' data-transitionSpeed=5000>content<div>
8090
```
81-
82-
> **current ** or **data-current** (default: 0)
91+
### Background Image Directives
92+
93+
The following are options used to define which background image and transitions are used.
94+
95+
> **current ** or **data-current** (default: 0) [Number]
8396
>> Given the list of images, current defines which image to use first. If `randomize` is set to `true`, then current is not used.
84-
>> <div data-current=0>content</div>
8597
86-
> **images** or **data-images** (default: [])
87-
>> List of images to use to create the background slideshow.
98+
> **images** or **data-images** (default: []) [Array of Strings]
99+
>> List of images to use to create the background slideshow.
100+
101+
> **transitionDelay** or **data-transitionDelay** (default: 5000 or 5 seconds) [Number]
102+
>> Amount of milliseconds to wait before starting the next transition to the next image.
103+
104+
> **transitionSpeed** or **data-transitionSpeed** (default: 3000 or 3 seconds) [Number]
105+
>> Amount of milliseconds for the transition effect to take
106+
107+
> **transitionEffect** or **data-transitionEffect** (default: fade-in) [String]
108+
>> The type of animation for the transition effect. Currently only 'fade-in' is implemented.
109+
110+
> **randomize** or **data-randomize** (default: false) [Boolean]
111+
>> true - The images selected for the transition are picked randomly and not sequentially.
112+
>> false - The images selected for the transition are picked sequentially starting from `current`.
113+
114+
> **initialBackground** or **data-initialBackground** (default: null) [Number, 'random', url]
115+
>> If set to anything other than null, then pick a background image from the list of images for the given element.
116+
>> Number - A number between 0 and the length of the `images` array. [0, images.length). The background of the element is set to this image in the `images` array.
117+
>> 'random' - The word 'random' indicate to pick a random image from the list of images in the `images` array to use as the initial background.
118+
>> image url - The url to an image will be used as the background image for this element.
119+
120+
> **debug** or **data-debug** (default: false) [Boolean]
121+
>> true - Print debug messages to the log.console for debugging purposes.
122+
>> false - No debug messages
123+
124+
### Event Handlers
125+
126+
Events handlers will be invoked for different events. All event handlers are defaulted to null.
127+
128+
> **beforeInit** - arguments (element, settings)
129+
>> Event triggered before any of the processing is started.
130+
131+
> **afterInit** arguments (element, settings)
132+
>> Event triggered after the processing is completed and the timer is set
133+
134+
> **beforeChange** arguments (element, settings, nextImage)
135+
>> Event triggered before the transition from the existing image to the next image. The current image can be accessed using $(element).css("background-image")
136+
137+
> **afterChange** arguments (element, settings, currentImage)
138+
>> Event triggered after the transition from current image to the next image is complete.

src/jquery-bg-slideshow.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@
212212
debug(settings.debug, "Calling timer for element [" + element + "]");
213213
var nextImage = getNextImage(settings);
214214
debug(settings.debug, "Next image is [" + nextImage + "]");
215+
if (settings.eventHandlers.beforeChange) {
216+
settings.eventHandlers.beforeChange(element, settings, nextImage);
217+
}
215218
settings.cloned = $(element).clone();
216219
$(settings.cloned).addClass("cloned").css({
217220
"z-index": -100,
@@ -230,6 +233,9 @@
230233
});
231234
var removed = $(settings.cloned).remove();
232235
debug(settings.debug, "Total removed [" + removed.length + "]");
236+
if (settings.eventHandlers.afterChange) {
237+
settings.eventHandlers.afterChange(element, settings, nextImage);
238+
}
233239
settings.timerId = setTimeout(timeoutEvent, settings.transitionDelay, element, settings);
234240
});
235241
}

0 commit comments

Comments
 (0)