File tree Expand file tree Collapse file tree 5 files changed +39
-0
lines changed Expand file tree Collapse file tree 5 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,8 @@ proto.settle = function( previousX ) {
127127 this . positionSlider ( ) ;
128128 this . dispatchEvent ( 'settle' , null , [ this . selectedIndex ] ) ;
129129 }
130+
131+ this . checkVisibility ( ) ;
130132} ;
131133
132134proto . shiftWrapCells = function ( x ) {
Original file line number Diff line number Diff line change @@ -83,6 +83,8 @@ proto.updateDraggable = function() {
8383 // disable dragging if less than 2 slides. #278
8484 if ( this . options . draggable == '>1' ) {
8585 this . isDraggable = this . slides . length > 1 ;
86+ } else if ( this . options . draggable === 'onOverflow' ) {
87+ this . isDraggable = this . viewport . scrollWidth > this . viewport . offsetWidth ;
8688 } else {
8789 this . isDraggable = this . options . draggable ;
8890 }
Original file line number Diff line number Diff line change @@ -757,6 +757,27 @@ proto.queryCell = function( selector ) {
757757 return this . getCell ( selector ) ;
758758} ;
759759
760+ proto . checkVisibility = function ( ) {
761+ var viewportX = this . viewport . getBoundingClientRect ( ) . x ;
762+ var viewportWidth = this . viewport . offsetWidth ;
763+
764+ this . cells . forEach ( function ( cell ) {
765+ var cellX = cell . element . getBoundingClientRect ( ) . x - viewportX ;
766+ var isVisible = (
767+ ( cellX + cell . size . innerWidth > viewportX ) && ( cellX + cell . size . innerWidth < viewportWidth ) ||
768+ ( cellX > viewportX ) && ( cellX < viewportWidth )
769+ ) ;
770+
771+ if ( isVisible ) {
772+ cell . element . classList . add ( 'is-visible' ) ;
773+ cell . element . removeAttribute ( 'aria-hidden' ) ;
774+ } else {
775+ cell . element . classList . remove ( 'is-visible' ) ;
776+ cell . element . setAttribute ( 'aria-hidden' , true ) ;
777+ }
778+ } ) ;
779+ } ;
780+
760781// -------------------------- events -------------------------- //
761782
762783proto . uiChange = function ( ) {
Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ proto.getLastCell = function() {
5151} ;
5252
5353proto . select = function ( ) {
54+ this . parent . checkVisibility ( ) ;
55+
5456 this . cells . forEach ( function ( cell ) {
5557 cell . select ( ) ;
5658 } ) ;
Original file line number Diff line number Diff line change @@ -143,6 +143,18 @@ <h2>contain, few</h2>
143143
144144 < h2 > watch, activate > 900px</ h2 >
145145
146+ < h2 > contain, only draggable if overflow</ h2 >
147+
148+ < div class ="container variable-width js-flickity "
149+ data-flickity-options ='{ "contain": true, "cellAlign": "left", "draggable": "onOverflow" } '>
150+ < div class ="cell n1 "> 1</ div >
151+ < div class ="cell n2 "> 2</ div >
152+ < div class ="cell n3 "> 3</ div >
153+ < div class ="cell n4 "> 4</ div >
154+ < div class ="cell n5 "> 5</ div >
155+ < div class ="cell n6 "> 6</ div >
156+ </ div >
157+
146158 < div id ="gallery5 " class ="container variable-width js-flickity "
147159 data-flickity-options ='{ "wrapAround": true, "watchCSS": true } '>
148160 < div class ="cell n1 w3 "> </ div >
You can’t perform that action at this time.
0 commit comments