Skip to content

Commit b2e95cd

Browse files
committed
Created a way to highlight the current image slide control.
1 parent 46724dc commit b2e95cd

4 files changed

+33
-2
lines changed

src/css/jquery-bg-slideshow-min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/jquery-bg-slideshow.css

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@
3737
cursor: pointer;
3838
}
3939

40+
/*
41+
* This is the class that highlights which image is being displayed
42+
* within the list control. That is, the small 'ball' on the bottom
43+
* of the page.
44+
*/
45+
.jquery-bg-slideshow-list-control-image-active-element {
46+
background-color: red;
47+
height: 10px;
48+
width: 10px;
49+
border-radius: 10px;
50+
transition: background-color 0.5s ease;
51+
}
52+
4053
/*
4154
* This is the class used to store the cloned element. This
4255
* will be in the background as the other one fades out.

src/js/jquery-bg-slideshow-min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/jquery-bg-slideshow.js

+18
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
var wrappedElement = $(element).css("position", "absolute");
196196
createImageSlideControls(element, wrappedElement.parent(), settings);
197197
debug(settings.debug, "Setting timeout for element [" + element + "]");
198+
updateCurrentSlideElement(settings, settings.current);
198199
settings.timerId = setTimeout(timeoutEvent, settings.transitionDelay, element, settings);
199200
}
200201

@@ -226,11 +227,16 @@
226227
var imageOffset = parseInt(id.match(/-image(\d+)/)[1]);
227228
settings.current = imageOffset + 1;
228229
$(element).css("background-image", "url(" + settings.images[imageOffset] + ")");
230+
updateCurrentSlideElement(settings, settings.current - 1);
229231
console.log("clicked on [" + $(this).attr("id") + "]");
230232
});
231233
}
232234
}
233235

236+
/**
237+
* Given an element, if it has a id attribute, then return it otherwise create a unique
238+
* id and return it.
239+
*/
234240
function getUniqueId(element) {
235241
var id = $(element).attr("id");
236242
if (!id) {
@@ -239,6 +245,9 @@
239245
return id;
240246
}
241247

248+
/**
249+
* Generate a unique id based on random character and current date in ms.
250+
*/
242251
function generateUniqueId() {
243252
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
244253
var rval = characters.charAt(Math.floor(Math.random() * characters.length)) + Date.now();
@@ -310,10 +319,19 @@
310319
if (settings.eventHandlers.afterChange) {
311320
settings.eventHandlers.afterChange(element, settings, nextImage);
312321
}
322+
updateCurrentSlideElement(settings, settings.current);
313323
settings.timerId = setTimeout(timeoutEvent, settings.transitionDelay, element, settings);
314324
});
315325
}
316326

327+
function updateCurrentSlideElement(settings, current) {
328+
if (settings.slideControls.enabled) {
329+
var id = "#" + settings.uniqueId + "-image" + current;
330+
$("[id^='" + settings.uniqueId + "-image']").removeClass("jquery-bg-slideshow-list-control-image-active-element");
331+
$(id).addClass("jquery-bg-slideshow-list-control-image-active-element");
332+
}
333+
}
334+
317335
/**
318336
* Preload all of the images so that there will be no delay in showing
319337
* the background.

0 commit comments

Comments
 (0)