@@ -120,7 +120,7 @@ Flickity.prototype._create = function() {
120120 this . element . flickityGUID = id ; // expando
121121 instances [ id ] = this ; // associate via id
122122 // initial properties
123- this . selectedIndex = this . options . initialIndex || 0 ;
123+ this . selectedIndex = 0 ;
124124 // how many frames slider has been in same position
125125 this . restingFrames = 0 ;
126126 // initial physics properties
@@ -188,8 +188,19 @@ Flickity.prototype.activate = function() {
188188
189189 this . emit ( 'activate' ) ;
190190
191- this . positionSliderAtSelected ( ) ;
192- this . select ( this . selectedIndex ) ;
191+ var index ;
192+ var initialIndex = this . options . initialIndex ;
193+ if ( this . isInitActivated ) {
194+ index = this . selectedIndex ;
195+ } else if ( initialIndex !== undefined ) {
196+ index = this . cells [ initialIndex ] ? initialIndex : 0 ;
197+ } else {
198+ index = 0 ;
199+ }
200+ // select instantly
201+ this . select ( index , false , true ) ;
202+ // flag for initial activation, for using initialIndex
203+ this . isInitActivated = true ;
193204} ;
194205
195206// slider positions the cells
@@ -420,8 +431,9 @@ Flickity.prototype.dispatchEvent = function( type, event, args ) {
420431/**
421432 * @param {Integer } index - index of the cell
422433 * @param {Boolean } isWrap - will wrap-around to last/first if at the end
434+ * @param {Boolean } isInstant - will immediately set position at selected cell
423435 */
424- Flickity . prototype . select = function ( index , isWrap ) {
436+ Flickity . prototype . select = function ( index , isWrap , isInstant ) {
425437 if ( ! this . isActive ) {
426438 return ;
427439 }
@@ -439,13 +451,18 @@ Flickity.prototype.select = function( index, isWrap ) {
439451 if ( this . options . wrapAround || isWrap ) {
440452 index = utils . modulo ( index , len ) ;
441453 }
442-
443- if ( this . cells [ index ] ) {
444- this . selectedIndex = index ;
445- this . setSelectedCell ( ) ;
454+ // bail if invalid index
455+ if ( ! this . cells [ index ] ) {
456+ return ;
457+ }
458+ this . selectedIndex = index ;
459+ this . setSelectedCell ( ) ;
460+ if ( isInstant ) {
461+ this . positionSliderAtSelected ( ) ;
462+ } else {
446463 this . startAnimation ( ) ;
447- this . dispatchEvent ( 'cellSelect' ) ;
448464 }
465+ this . dispatchEvent ( 'cellSelect' ) ;
449466} ;
450467
451468Flickity . prototype . previous = function ( isWrap ) {
0 commit comments