Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overflow-y of body is not removed on lightbox close #110

Closed
NickHatBoecker opened this issue Sep 14, 2022 · 3 comments
Closed

overflow-y of body is not removed on lightbox close #110

NickHatBoecker opened this issue Sep 14, 2022 · 3 comments
Labels
bug Something isn't working question Further information is requested

Comments

@NickHatBoecker
Copy link

I'm using the version for Vue2. When closing the lightbox via ESC, close button or mask the body element stil has overflow-y: hidden set.

Currently I'm using a workaround to fix this.
Also index isn't reactive. I have to use @on-index-change to update current index variable.

<template>
    <vue-easy-lightbox
        moveDisabled
        scrollDisabled
        :visible="show"
        :imgs="images"
        :index="currentIndex"
        @on-index-change="onIndexChange"
        @on-error="close"
        @hide="close"
    >
        <template #toolbar>
            <span></span>
        </template>
    </vue-easy-lightbox>
<template>

<script>
import VueEasyLightbox from 'vue-easy-lightbox'

export default {
    components: { VueEasyLightbox },

    data: () => ({ currentIndex: 0, show: false }),

    mounted () {
        setTimeout(() => {
            // Timeout in order to load the first image
            this.show = true
        }, 2000)
    },

    computed: {
        images () {
            return this.$store.getters.images
        },
    },

    methods: {
        close () {
            document.querySelector('body').style['overflow-y'] = 'visible'
        },

        onIndexChange (oldIndex, newIndex) {
            this.currentIndex = newIndex
        },
    },
}
</script>
@XiongAmao XiongAmao added bug Something isn't working question Further information is requested labels Sep 15, 2022
@XiongAmao
Copy link
Owner

Hi,

Neither index nor visible is reactive. By design, you should control it by yourself.
This means that you can change visible or index at anytime to activate vue-easy-lightbox or switch images.

overflow-y: hidden will be clear when visible change back to false.

Maybe you can provide a repo and I'll see what the issue is.

disableScrolling() {
if (!document) return
this.lastBodyStyleOverflowY = document.body.style.overflowY
document.body.style.overflowY = 'hidden'
}
enableScrolling() {
if (!document) return
document.body.style.overflowY = this.lastBodyStyleOverflowY
}
// watch
@Watch('visible', { immediate: true })
onVisibleChanged(visible: boolean) {
if (visible) {
this.init()
this.$nextTick(() => {
on(this.$refs.modal as Element, 'touchmove', (e: Event) => {
e.preventDefault()
})
if (this.scrollDisabled) {
this.disableScrolling()
}
})
} else {
if (this.scrollDisabled) {
this.enableScrolling()
}
}
}
@Watch('index')
onIndexChange(newIndex: number) {
if (newIndex < 0 || newIndex >= this.imgList.length) {
return
}
this.setIndex(newIndex)
}

@aasutossh
Copy link

So I was using two <vue-easy-lightbox>es with same :visible option.
After removing one of them, it worked.

XiongAmao added a commit that referenced this issue Nov 25, 2022
fix `overflow-y: hidden` is not removed on lightbox close #116 #110
@XiongAmao
Copy link
Owner

The issue was fixed in v1.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants