@@ -36,14 +36,6 @@ if (_ieVersion < 10) {
3636 } ;
3737}
3838
39- function handleCaptionMousewheel ( event ) {
40- event . stopPropagation ( ) ;
41- }
42-
43- function handleCaptionMouseDown ( event ) {
44- event . stopPropagation ( ) ;
45- }
46-
4739class ReactImageLightbox extends Component {
4840 constructor ( props ) {
4941 super ( props ) ;
@@ -86,14 +78,13 @@ class ReactImageLightbox extends Component {
8678 this . handleOuterMousewheel = this . handleOuterMousewheel . bind ( this ) ;
8779 this . handleOuterTouchStart = this . handleOuterTouchStart . bind ( this ) ;
8880 this . handleOuterTouchMove = this . handleOuterTouchMove . bind ( this ) ;
81+ this . handleCaptionMousewheel = this . handleCaptionMousewheel . bind ( this ) ;
8982 this . handleWindowResize = this . handleWindowResize . bind ( this ) ;
9083 this . handleZoomInButtonClick = this . handleZoomInButtonClick . bind ( this ) ;
9184 this . handleZoomOutButtonClick = this . handleZoomOutButtonClick . bind ( this ) ;
9285 this . requestClose = this . requestClose . bind ( this ) ;
9386 this . requestMoveNext = this . requestMoveNext . bind ( this ) ;
9487 this . requestMovePrev = this . requestMovePrev . bind ( this ) ;
95- this . handleCaptionMousewheel = handleCaptionMousewheel ;
96- this . handleCaptionMouseDown = handleCaptionMouseDown ;
9788 }
9889
9990 componentWillMount ( ) {
@@ -686,6 +677,23 @@ class ReactImageLightbox extends Component {
686677 this . changeZoom ( this . state . zoomLevel - ZOOM_BUTTON_INCREMENT_SIZE ) ;
687678 }
688679
680+ handleCaptionMousewheel ( event ) {
681+ event . stopPropagation ( ) ;
682+
683+ if ( ! this . caption ) {
684+ return ;
685+ }
686+
687+ const height = this . caption . getBoundingClientRect ( ) . height ;
688+ const scrollHeight = this . caption . scrollHeight ;
689+ const scrollTop = this . caption . scrollTop ;
690+ if ( ( event . deltaY > 0 && ( height + scrollTop ) >= scrollHeight ) ||
691+ ( event . deltaY < 0 && scrollTop <= 0 )
692+ ) {
693+ event . preventDefault ( ) ;
694+ }
695+ }
696+
689697 // Detach key and mouse input events
690698 isAnimating ( ) {
691699 return this . state . shouldAnimate || this . state . isClosing ;
@@ -1160,18 +1168,19 @@ class ReactImageLightbox extends Component {
11601168 </ ul >
11611169 </ div >
11621170
1163- { ! this . props . imageCaption ? '' :
1164- < div // Image caption
1165- onWheel = { this . handleCaptionMousewheel }
1166- onMouseDown = { this . handleCaptionMouseDown }
1167- className = { `ril-caption ${ styles . caption } ` }
1168- >
1169- < div
1170- className = { `ril-caption-content ${ styles . captionContent } ` }
1171+ { this . props . imageCaption &&
1172+ < div // Image caption
1173+ onWheel = { this . handleCaptionMousewheel }
1174+ onMouseDown = { event => event . stopPropagation ( ) }
1175+ className = { `ril-caption ${ styles . caption } ` }
1176+ ref = { ( el ) => { this . caption = el ; } }
11711177 >
1172- { this . props . imageCaption }
1178+ < div
1179+ className = { `ril-caption-content ${ styles . captionContent } ` }
1180+ >
1181+ { this . props . imageCaption }
1182+ </ div >
11731183 </ div >
1174- </ div >
11751184 }
11761185
11771186 </ div >
0 commit comments