Skip to content

Commit

Permalink
add option initialIndex
Browse files Browse the repository at this point in the history
Allow the slider to start at any slide when it is first
initialized. Previously, it would always start at slide index 0.
  • Loading branch information
Daniel Johnson committed Apr 5, 2017
1 parent 5722216 commit cf19cfd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 5 additions & 3 deletions src/lory.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,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];
Expand Down Expand Up @@ -266,7 +268,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;
Expand All @@ -280,7 +282,7 @@ export function lory (slider, opts) {
}

if (rewindOnResize) {
index = 0;
index = initialIndex;
} else {
ease = null;
rewindSpeed = 0;
Expand Down

0 comments on commit cf19cfd

Please sign in to comment.