File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change
1
+ # 1.7.0 - Apr 2020
2
+
3
+ *** (FEATURE)*** Add support for IntersectionObserver and disable autoplay functionality when the carousel is outside the viewport
4
+
1
5
# 1.6.0 - Feb 2020
2
6
3
7
*** (FEATURE)*** Add ` onSlideTransitioned ` callback and updated ` arrows ` prop to support custom arrows
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-img-carousel" ,
3
- "version" : " 1.6 .0" ,
3
+ "version" : " 1.7 .0" ,
4
4
"description" : " Provides an image carousel React component." ,
5
5
"main" : " lib/index.js" ,
6
6
"repository" : {
Original file line number Diff line number Diff line change @@ -177,6 +177,21 @@ export default class Carousel extends Component {
177
177
}
178
178
179
179
window . addEventListener ( 'resize' , this . calcLeftOffset , false ) ;
180
+
181
+ if ( window . IntersectionObserver ) {
182
+ this . _observer = new window . IntersectionObserver ( entries => {
183
+ if ( ! this . props . autoplay ) {
184
+ return ;
185
+ }
186
+
187
+ if ( entries && entries [ 0 ] && entries [ 0 ] . isIntersecting ) {
188
+ this . startAutoplay ( ) ;
189
+ } else {
190
+ clearTimeout ( this . _autoplayTimer ) ;
191
+ }
192
+ } ) ;
193
+ this . _observer . observe ( this . _containerRef ) ;
194
+ }
180
195
}
181
196
182
197
componentWillUnmount ( ) {
@@ -187,6 +202,7 @@ export default class Carousel extends Component {
187
202
clearTimeout ( this . _autoplayTimer ) ;
188
203
clearTimeout ( this . _retryTimer ) ;
189
204
clearTimeout ( this . _initialLoadTimer ) ;
205
+ this . _observer && this . _observer . unobserve ( this . _containerRef ) ;
190
206
this . _isMounted = false ;
191
207
}
192
208
@@ -436,7 +452,7 @@ export default class Carousel extends Component {
436
452
const controls = this . getControls ( ) ;
437
453
438
454
return (
439
- < div className = { classes } style = { containerStyle } >
455
+ < div className = { classes } style = { containerStyle } ref = { c => { this . _containerRef = c ; } } >
440
456
< div className = 'carousel-container-inner' style = { innerContainerStyle } >
441
457
{
442
458
controls . filter ( Control => {
You can’t perform that action at this time.
0 commit comments