Skip to content

Commit

Permalink
Bug fix for #1082.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjerleke committed Jan 7, 2025
1 parent 1b01939 commit 4f97f20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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
3 changes: 2 additions & 1 deletion playgrounds/embla-carousel-playground-vanilla/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
toggleDotBtnsActive
} from './Carousel/setupDots'
import './main.css'
import Autoplay from 'embla-carousel-autoplay'

const injectBaseStyles = (): void => {
const styleElement = document.createElement('style')
Expand Down Expand Up @@ -55,7 +56,7 @@ injectBaseStyles()

const SLIDE_COUNT = 6
const OPTIONS: EmblaOptionsType = {}
const PLUGINS: EmblaPluginType[] = []
const PLUGINS: EmblaPluginType[] = [Autoplay({ delay: 2000 })]

const emblaNodes = <HTMLElement[]>(
Array.from(document.querySelectorAll('.embla'))
Expand Down

0 comments on commit 4f97f20

Please # to comment.