Snorlax Posted August 2, 2024 Posted August 2, 2024 Hello team,I hope to use Flip in Nuxt3 to achieve a caterpillar effect,so here my code: https://codesandbox.io/p/devbox/flip-nuxt3-dd792k This example was copied from the official demo: See the Pen Yzdzxem by GreenSock (@GreenSock) on CodePen. but the difference is that I used the Nuxt3(Vue3). But the result was not as expected, the newly generated DOM elements had no style like below. I have thought that maybe I should not manipulate DOM in Vue, but if I only change responsive data, then it only changes the order of data and does not display Flip animations. So where did I go wrong?Thanks! See the Pen flip-nuxt3-dd792k by p (@p) on CodePen.
Cassie Posted August 2, 2024 Posted August 2, 2024 Hiya! I haven't seen this before but it seems like it's an issue with dynamic content not inheriting scoped styles https://stackoverflow.com/questions/43052364/vue-js-how-can-i-make-dynamically-created-html-use-scoped-css Quote Dynamically Generated Content DOM content created with v-html are not affected by scoped styles, but you can still style them using deep selectors. There doesn't appear to be a VueJS specific way of doing it. It sounds like your best option is to either style in-line in your highlight function's output, or use a global class. This isn't a GSAP thing I'm afraid so I can't offer much more assistance here Good luck 1
Rodrigo Posted August 2, 2024 Posted August 2, 2024 Hi, As Cassie mentions this is related to the styling of the cards being scoped and the fact that you're manipulating the DOM directly. You can either use a global style for just those elements in a global styles file, which shouldn't be too costly, or you can update the DOM using a reactive property in order to force a re-render and add the elements using Vue instead and then the scoped styles would work as expected. Regardless of the route you end up choosing, I would strongly recommend you to not update your DOM like you're doing it now, since any other re-render up the component tree could reset your DOM to what it was before you used the click method. Happy Tweening!
Snorlax Posted August 3, 2024 Author Posted August 3, 2024 Thank you very much. Inspired by you, I have successfully found a solution to this problem. The first one is that, following Cassie's guidance, I learned to use Flip to manipulate DOM. In this case, I need to use a depth selector to solve the problem that the DOM elements generated by Flip do not enjoy the scope style of Vue.Just need to add " :deep". The second option, as Rodrigo mentioned, is not recommended to operate DOM in Vue, so I changed the method and used Flip for sorting without involving DOM addition and deletion. In this case, I don't need to use a depth selector, but the only flaw is that its animation effect is not what I most want. 3
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now