Skip to content

Commit

Permalink
Fix image flicker when opening the lightbox to a specific image
Browse files Browse the repository at this point in the history
* Image transitions are enabled only after the lightbox fade in completes
* Image transitions are disabled as soon as the lightbox starts fading out
  • Loading branch information
janosrusiczki committed Apr 27, 2020
1 parent 5a6b4e2 commit 8f78a82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/LightBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<transition
mode="out-in"
name="vue-lb-content-transition"
@afterEnter="enableImageTransition"
@beforeLeave="disableImageTransition"
>
<div
v-if="media && media.length > 0"
Expand Down Expand Up @@ -30,7 +32,7 @@
>
<transition
mode="out-in"
name="vue-lb-modal-image-transition"
:name="modalImageTransitionName"
>
<img
v-if="media[select].type !== 'video'"
Expand Down Expand Up @@ -264,6 +266,7 @@ export default {
return {
select: this.startAt,
lightBoxOn: this.showLightBox,
modalImageTransitionName: 'vue-lb-modal-image-no-transition',
timer: null,
}
},
Expand Down Expand Up @@ -408,6 +411,14 @@ export default {
previousImage() {
this.$set(this, 'select', (this.select + this.media.length - 1) % this.media.length)
},
enableImageTransition() {
this.modalImageTransitionName = 'vue-lb-modal-image-transition'
},
disableImageTransition() {
this.modalImageTransitionName = 'vue-lb-modal-image-no-transition'
}
},
}
</script>
Expand Down
10 changes: 10 additions & 0 deletions src/components/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ img.vue-lb-modal-image {
opacity: 0;
}

.vue-lb-modal-image-no-transition-enter-active,
.vue-lb-modal-image-no-transition-leave-active {
transition: none;
}

.vue-lb-modal-image-no-transition-enter,
.vue-lb-modal-image-no-transition-leave-to {
opacity: 0;
}

.vue-lb-content-transition-enter-active,
.vue-lb-content-transition-leave-active {
transition: opacity .2s ease;
Expand Down

0 comments on commit 8f78a82

Please sign in to comment.