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

Flickity inside vue transitions #12

Closed
b8ne opened this issue May 29, 2017 · 6 comments
Closed

Flickity inside vue transitions #12

b8ne opened this issue May 29, 2017 · 6 comments

Comments

@b8ne
Copy link

b8ne commented May 29, 2017

I have a blog style setup, with a flickity slider for each article.
I then have a side bar with a list of articles, and on click i transition the articles.
During this transition the flickity object seems to lose its styling, and all images breifly stack relative.
Any idea how to prevent this?

@ghost
Copy link

ghost commented May 31, 2017

Hard to say on this without debugging the UI, but it might be the .destroy() method removing flickity and its core styling while the component is unmounted and animated away. You could try modifying the wrapper so flickity is not destroyed before the transition finishes or you could hardcode some of the necessary styles in your codebase so they remain after flickity is unmounted or you could use <keep-alive> above the component so the beforeDestroy() hook is never triggered.

@chasegiunta
Copy link

@b8ne I know it's been a while, but were you ever able to find a workaround for this? Also running into this issue.

@elHornair
Copy link

I had the same problem and was able to avoid it by using keep-alive as suggested by @mystrdat. Check the docs for details. Note that keep-alive needs to be around your component but inside the transition.
/cc @chasegiunta @b8ne

@EnMod
Copy link

EnMod commented May 18, 2018

I found that this problem persists in my Nuxt project, and the only way to solve it was to comment out the entire beforeDestroy() hook in the package's src/flickity.vue component. Not sure if that will cause other issues down the road but it's working as of right now.

@1deadpixl
Copy link

1deadpixl commented Apr 26, 2019

I found that this problem persists in my Nuxt project, and the only way to solve it was to comment out the entire beforeDestroy() hook in the package's src/flickity.vue component.

Had the same problem using Nuxt and this is a good fix, except…

Not sure if that will cause other issues down the road but it's working as of right now.

…you still need to destroy the Flickity instance(s) after being done with them.

My case was that I wanted to scroll to the top of the page during the leave transition and all my Flickitys were gone before the scroll even started, leaving the page looking gnarly. After disabling the beforeDestroy hook in vue-flickity, I load up the data object of my GSAP tween with all my Flickity references and destroy() them after the leaving animation completes.

All this is necessary because the leave, beforeDestroy and destroy hooks run immediately on a route change and all references get destroyed before the animation finishes so we have to keep them around somewhere.

Update
To disable the hook persistently without worrying about changes from package updates or npm clean installs, the beforeDestroy method can be set to undefined when defining the plugin.

/* plugins/flickity.js */

import Vue from "vue";
import Flickity from "vue-flickity";
import "flickity-imagesloaded";
import "flickity-fade";

Flickity.beforeDestroy = undefined;
Vue.component("flickity", Flickity);

@chrisjansky
Copy link

Has anyone managed to solve it when importing vue-flickity only inside a Nuxt single page, like this:

export default {
  components: {
    Flickity: () => import("vue-flickity")
  }
}

Thanks for any pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants