chore(docs): abort animation if task was cancelled
This commit is contained in:
@@ -88,7 +88,7 @@ const path = computed(() => getSmoothStepPath(props))
|
|||||||
|
|
||||||
watch(isCancelled, (isCancelled) => {
|
watch(isCancelled, (isCancelled) => {
|
||||||
if (isCancelled) {
|
if (isCancelled) {
|
||||||
isAnimating.value = false
|
reset()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -110,24 +110,19 @@ watch(edgePoint, (point) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const currLength = pathEl.getTotalLength()
|
const nextLength = pathEl.getTotalLength()
|
||||||
|
|
||||||
if (currentLength.value !== currLength) {
|
if (currentLength.value !== nextLength) {
|
||||||
return runAnimation()
|
runAnimation()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
labelPosition.value = pathEl.getPointAtLength(point)
|
labelPosition.value = pathEl.getPointAtLength(point)
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(isFinished, async (isFinished) => {
|
watch(isFinished, (isFinished) => {
|
||||||
if (isFinished) {
|
if (isFinished) {
|
||||||
await runAnimation()
|
runAnimation()
|
||||||
|
|
||||||
nextTick(() => {
|
|
||||||
edgePoint.value = 0
|
|
||||||
currentLength.value = 0
|
|
||||||
labelPosition.value = { x: 0, y: 0 }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -138,14 +133,14 @@ async function runAnimation() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nextTick(() => {
|
|
||||||
isAnimating.value = true
|
|
||||||
})
|
|
||||||
|
|
||||||
const totalLength = pathEl.getTotalLength()
|
const totalLength = pathEl.getTotalLength()
|
||||||
|
|
||||||
const from = edgePoint.value || 0
|
const from = edgePoint.value || 0
|
||||||
|
|
||||||
|
labelPosition.value = pathEl.getPointAtLength(from)
|
||||||
|
|
||||||
|
isAnimating.value = true
|
||||||
|
|
||||||
if (currentLength.value !== totalLength) {
|
if (currentLength.value !== totalLength) {
|
||||||
currentLength.value = totalLength
|
currentLength.value = totalLength
|
||||||
}
|
}
|
||||||
@@ -153,9 +148,19 @@ async function runAnimation() {
|
|||||||
await executeTransition(edgePoint, from, totalLength, {
|
await executeTransition(edgePoint, from, totalLength, {
|
||||||
transition: TransitionPresets.easeInOutCubic,
|
transition: TransitionPresets.easeInOutCubic,
|
||||||
duration: Math.max(1500, totalLength / 2),
|
duration: Math.max(1500, totalLength / 2),
|
||||||
|
abort: () => !isAnimating.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
isAnimating.value = false
|
reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
nextTick(() => {
|
||||||
|
edgePoint.value = 0
|
||||||
|
currentLength.value = 0
|
||||||
|
labelPosition.value = { x: 0, y: 0 }
|
||||||
|
isAnimating.value = false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user