Skip to content

Commit

Permalink
Merge pull request #1101 from davidjerleke/bug/#1082
Browse files Browse the repository at this point in the history
[Bug]: Autoplay never starts if page with carousel is loaded in inactive browser tab
  • Loading branch information
davidjerleke authored Jan 7, 2025
2 parents 1b01939 + 6727eed commit acad2f5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/embla-carousel-autoplay/src/components/Autoplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function Autoplay(userOptions: AutoplayOptionsType = {}): AutoplayType {
eventStore.add(emblaApi.containerNode(), 'focusout', startAutoplay)
}

if (options.playOnInit && !documentIsHidden()) startAutoplay()
if (options.playOnInit) startAutoplay()
}

function destroy(): void {
Expand Down Expand Up @@ -124,6 +124,10 @@ function Autoplay(userOptions: AutoplayOptionsType = {}): AutoplayType {

function startAutoplay(): void {
if (destroyed) return
if (documentIsHidden()) {
playOnDocumentVisible = true
return
}
if (!autoplayActive) emblaApi.emit('autoplay:play')

setTimer()
Expand Down

0 comments on commit acad2f5

Please sign in to comment.