naive handling of preventing image changes during already running transiiton

This commit is contained in:
ManjaroOne666 2019-01-24 10:48:35 +00:00
parent a9806efb60
commit 16e314d7cc
1 changed files with 28 additions and 3 deletions

View File

@ -2,14 +2,18 @@
<div class="background-image-loader"> <div class="background-image-loader">
<div class="background-container"> <div class="background-container">
<div class="background background-default"></div> <div class="background background-default"></div>
<transition name="fade-fast"> <transition name="fade-fast"
>
<div v-if="loadedImageUrl !== null" <div v-if="loadedImageUrl !== null"
class="background background-img background-blur" class="background background-img background-blur"
:style="backgroundBlurStyle" :style="backgroundBlurStyle"
> >
</div> </div>
</transition> </transition>
<transition name="fade"> <transition name="fade"
@beforeEnter="handleBeforeEnter"
@afterLeave="handleAfterLeave"
>
<div class="background background-img" <div class="background background-img"
:key="loadedImageUrl" :key="loadedImageUrl"
:style="backgroundStyle" :style="backgroundStyle"
@ -41,6 +45,8 @@ export default {
data () { data () {
return { return {
loadedImageUrl: null, loadedImageUrl: null,
isInTransition: false,
transitionTimeout: null,
} }
}, },
@ -66,7 +72,7 @@ export default {
watch: { watch: {
imageUrl () { imageUrl () {
if (this.imageUrl) { if (!this.isInTransition && this.imageUrl) {
this.setImage(this.imageUrl) this.setImage(this.imageUrl)
} }
}, },
@ -88,6 +94,25 @@ export default {
this.$emit('imageLoadError', err) this.$emit('imageLoadError', err)
}) })
}, },
handleBeforeEnter() {
// TOOD get the actual value programatically
let transitionDuration = 4000
this.isInTransition = true
clearTimeout(this.transitionTimeout)
this.transitionTimeout = setTimeout(() => {
this.isInTransition = false
if (this.imageUrl !== this.loadedImageUrl) {
this.setImage(this.imageUrl)
}
}, transitionDuration)
},
handleAfterLeave() {
}
}, },
} }
</script> </script>