diff --git a/README.md b/README.md
index 54221d5..882cf62 100644
--- a/README.md
+++ b/README.md
@@ -284,6 +284,11 @@ li {
cubic bezier easing functions: http://easings.net/de |
default: 'ease' |
+
+ initialIndex |
+ the slide index to show when the slider is initialized |
+ default: 0 |
+
classNameFrame |
class name for slider frame |
diff --git a/index.html b/index.html
index 7f9868f..85e324a 100644
--- a/index.html
+++ b/index.html
@@ -700,6 +700,11 @@ Options
time for the snapBack of the slider if the slide attempt was not valid |
default: 200 |
+
+ initialIndex |
+ the slide index to show when the slider is initialized |
+ default: 0 |
+
ease |
cubic bezier easing functions: http://easings.net/de |
diff --git a/src/defaults.js b/src/defaults.js
index 9973bc0..5615b6e 100644
--- a/src/defaults.js
+++ b/src/defaults.js
@@ -44,6 +44,12 @@ export default {
*/
infinite: false,
+ /**
+ * the slide index to show when the slider is initialized.
+ * @initialIndex {number}
+ */
+ initialIndex: 0,
+
/**
* class name for slider frame
* @classNameFrame {string}
diff --git a/src/lory.js b/src/lory.js
index b321f4e..2944bdf 100644
--- a/src/lory.js
+++ b/src/lory.js
@@ -243,9 +243,11 @@ export function lory (slider, opts) {
classNamePrevCtrl,
classNameNextCtrl,
enableMouseEvents,
- classNameActiveSlide
+ classNameActiveSlide,
+ initialIndex
} = options;
+ index = initialIndex;
frame = slider.getElementsByClassName(classNameFrame)[0];
slideContainer = frame.getElementsByClassName(classNameSlideContainer)[0];
prevCtrl = slider.getElementsByClassName(classNamePrevCtrl)[0];
@@ -298,7 +300,7 @@ export function lory (slider, opts) {
* reset function: called on resize
*/
function reset () {
- var {infinite, ease, rewindSpeed, rewindOnResize, classNameActiveSlide} = options;
+ var {infinite, ease, rewindSpeed, rewindOnResize, classNameActiveSlide, initialIndex} = options;
slidesWidth = slideContainer.getBoundingClientRect()
.width || slideContainer.offsetWidth;
@@ -312,7 +314,7 @@ export function lory (slider, opts) {
}
if (rewindOnResize) {
- index = 0;
+ index = initialIndex;
} else {
ease = null;
rewindSpeed = 0;
diff --git a/test/lory.test.js b/test/lory.test.js
index ab86d70..99547df 100644
--- a/test/lory.test.js
+++ b/test/lory.test.js
@@ -335,6 +335,26 @@ describe('lory()', function () {
});
});
});
+
+ describe('with initialIndex', function () {
+ beforeEach(function () {
+ instance = lory(element, {
+ initialIndex: 3
+ });
+ });
+
+ describe('called once', function() {
+ var expectedIndex = 2;
+
+ beforeEach(function () {
+ instance.prev();
+ });
+
+ it('index has to be 2 (one less than initialIndex)', function() {
+ assert.equal(instance.returnIndex(), expectedIndex);
+ });
+ });
+ });
});
describe('.destroy()', function () {