1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-26 21:39:08 +02:00

Use Page Visibility API in Carousel; fixes #17706

Avoids cycling carousels when the page isn't visible.
Closes #17710
Refs #15566
This commit is contained in:
Johann-S
2015-09-27 01:30:11 +02:00
committed by Chris Rebert
parent 9b12e5f495
commit 817d997b75
2 changed files with 17 additions and 2 deletions

View File

@@ -119,6 +119,13 @@ const Carousel = (($) => {
}
}
nextWhenVisible() {
// Don't call next when the page isn't visible
if (!document.hidden) {
this.next()
}
}
prev() {
if (!this._isSliding) {
this._slide(Direction.PREVIOUS)
@@ -152,7 +159,7 @@ const Carousel = (($) => {
if (this._config.interval && !this._isPaused) {
this._interval = setInterval(
$.proxy(this.next, this), this._config.interval
$.proxy(document.visibilityState ? this.nextWhenVisible : this.next, this), this._config.interval
)
}
}