#45 : Update autoplay
This commit is contained in:
@@ -60,11 +60,7 @@
|
|||||||
*/
|
*/
|
||||||
export let autoplay = false
|
export let autoplay = false
|
||||||
$: {
|
$: {
|
||||||
if (autoplay) {
|
applyAutoplayIfNeeded(autoplay)
|
||||||
applyAutoplay()
|
|
||||||
} else {
|
|
||||||
progressManager.reset()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -176,8 +172,19 @@
|
|||||||
pagesElement.append(first.cloneNode(true))
|
pagesElement.append(first.cloneNode(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function applyAutoplay() {
|
async function applyAutoplayIfNeeded(autoplay) {
|
||||||
await autoplayDirectionFnDescription[autoplayDirection]()
|
// prevent progress change if not infinite for first and last page
|
||||||
|
if (
|
||||||
|
!infinite && (
|
||||||
|
(autoplayDirection === NEXT && currentPageIndex === pagesCount - 1) ||
|
||||||
|
(autoplayDirection === PREV && currentPageIndex === 0)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
progressManager.reset()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
autoplay && await autoplayDirectionFnDescription[autoplayDirection]()
|
||||||
}
|
}
|
||||||
|
|
||||||
let cleanupFns = []
|
let cleanupFns = []
|
||||||
@@ -259,7 +266,7 @@
|
|||||||
disabled = false
|
disabled = false
|
||||||
|
|
||||||
const jumped = await jumpIfNeeded()
|
const jumped = await jumpIfNeeded()
|
||||||
!jumped && autoplay && applyAutoplay() // no need to wait it finishes
|
!jumped && applyAutoplayIfNeeded(autoplay) // no need to wait it finishes
|
||||||
}
|
}
|
||||||
|
|
||||||
async function showPage(pageIndex, options) {
|
async function showPage(pageIndex, options) {
|
||||||
|
|||||||
@@ -51,5 +51,6 @@ export class ProgressManager {
|
|||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
clearInterval(this.#interval)
|
clearInterval(this.#interval)
|
||||||
|
this.#onProgressValueChange(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user