Is there a way for me to smoothly switch between two nuxt pages, pausing for a child component transition or animation to complete before moving on?

Seeking guidance on transitions. Is it feasible to wait for a child transition/animation to finish before transitioning from one page to another?

For instance:

1) Home (Page Component)

a) Logo (Vue Component)

2) About (Page Component)

Upon clicking on the About option on the homepage, the aim is to animate the Logo component first, fade out the entire homepage, and then proceed to the About page.

Below is the relevant code:

Index.vue:

<template>
  <div class="home" style="opacity: 0">
    <Logo v-show="showChild"/>
    <nuxt-link to="/about">About</nuxt-link>
    <p>Homepage</p>
  </div>
</template>

<script>
import Logo from "~/components/Logo.vue";
import { TweenMax, CSSPlugin } from "gsap";

export default {
  components: {
    Logo
  },
  data() {
    return {
      showChild: true
    };
  },
  transition: {
    enter(el, done) {
      console.log("Enter Parent Home");
      this.showChild = true;
      TweenLite.to(el, 1, {
        opacity: 1,
        onComplete: done
      });
    },
    leave(el, done) {
      this.showChild = false;
      TweenLite.to(el, 1, {
        opacity: 0,
        onComplete: done
      });
      console.log("Leave Parent Home");
      console.log("Child Visible: " + this.showChild);
    },
    appear: true,
    css: false
  }
};
</script>

Logo.vue

<template>
  <transition @enter="enter" @leave="leave" mode="out-in" :css="false">
    <div style="display: block; width: 200px; height: 200px;">
      <img
        style="objec-fit: cover; width: 100%; height: 100%"
        src="https://images.unsplash.com/photo-1508138221679-760a23a2285b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1334&q=80"
      >
    </div>
  </transition>
</template>

<script>
export default {
  props: {
    showChild: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    enter(el, done) {
      console.log("Enter Child Home");
      TweenLite.fromTo(el, 1, { x: -100 }, { x: 0, onComplete: done });
    },
    leave(el, done) {
      console.log("Leave Child Home");
      TweenLite.to(el, 1, {
        x: -100,
        onComplete: done
      });
    }
  }
};
</script>

About.vue

<template>
  <div class="about" style="opacity: 0">
    <nuxt-link to="/">Home</nuxt-link>
    <p>About</p>
  </div>
</template>

<script>
export default {
  transition: {
    enter(el, done) {
      console.log("Enter Parent About");
      TweenLite.to(el, 1, {
        opacity: 1,
        onComplete: done
      });
    },
    leave(el, done) {
      console.log("Leave Parent About");
      TweenLite.to(el, 1, {
        opacity: 0,
        onComplete: done
      });
    },
    appear: true,
    css: false
  }
};
</script>

A sandbox has been set up as well.

https://codesandbox.io/s/codesandbox-nuxt-psks0

Encountering two ongoing issues:

1) The leave transition of the child component (Logo) is not triggering properly at present.

2) Is it achievable to complete the Child Component (Logo) transition first, followed by the home page transition, and finally route to the about page? Any insights on this?

Your assistance is greatly appreciated.

Regards, Chris

Answer №1

To implement a custom transition in your home.vue file, start by wrapping it as shown below:

<transition @enter="enter" @leave="leave" mode="out-in" :css="false">
   <client-only>
      <Logo v-if="showChild"/>
   </client-only>
</transition>

export default {
   data() {
      return {
         showChild: true
      };
   },
   methods: {
      enter(el, done) {
         console.log("Enter Child Home");
         TweenLite.fromTo(el, 1, { x: -100 }, { x: 0, onComplete: done });
      },
      leave(el, done) {
         console.log("Leave Child Home");
         TweenLite.to(el, 1, {
         x: -100,
         onComplete: this.$router.push("/about")
      });
    }
  }
}

Instead of using an nuxt-link, use a regular a tag or button and set showChild to false to trigger the leave method.

<button @click="showChild = false" />

At the end of the leave method, include this.$router.push("/about") to execute after the transition is complete. The logo should transition first, followed by the page transition.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it considered beneficial to use Observable as a static class member?

Lately, I have been diving into a new Angular project and noticed that the common way to share state between unrelated components is by using rxjs Subject/BehaviorSubject as static members within the class. For instance: export class AbcService { privat ...

Adding optional properties to TypeScript interfaces

As discussed in this post, the optional ? operator is commonly used to indicate that a function parameter can be omitted. But what is the significance of the ? operator when it appears on interface parameters? For instance, consider the following TypeScrip ...

The dynamic change of a required field property does not occur

I am facing an issue where one of my fields in the form should be mandatory or not based on a boolean variable. Even if the variable changes, the field always remains required. I'm puzzled about why my expressionProperties templateOptions.required is ...

Experiencing a problem with a loop structure in my code

I've been trying to create a loop that will increase the temperature by 10 degrees every 2 minutes. However, I'm struggling to figure out how to stop the temperature at 120 degrees after 16 minutes. Any suggestions on how to solve this issue? va ...

Show the button's value inside a div when clicked using Javascript and HTML

I am troubleshooting an issue where the value of a button is not displayed in the picked_letters div when the button is clicked, despite having the appropriate code in both the html and javascript files. The structure of the html file is as follows: < ...

Distinguishing each unique JavaScript property within an array of objects

I've been struggling with this problem for quite some time. I have an array of objects, focusing on the "00" object at the moment, and I am trying to group together the bestScore properties in a specific way: .. User Group apple .. User Group ba ...

Assign the value to the data property once the promise has been fulfilled

When developing my app, I encountered a challenge of connecting to the MySQL backend using Sequelize. Here is the code snippet that I am currently working with: export default { data () { return { username:'' ...

Vue Labyrinthine Design theme

Looking for some guidance from experienced developers out there! I'm currently exploring how to incorporate Mazeletter as a background feature for each page in an app project I've been working on. This is all new territory for me, so any assista ...

Comparing dynamic and static strings within objects using regex in JavaScript

Suppose there is an object with keys as strings containing dynamic values- let obj = { "/prodp/v1/engagemnt/{engID}/doc/{docID}": "roles_1", "/prodp/v1/engagemnt/{engID}/review/{reviewID}": "roles_2" } How can I find the value in the above object for the ...

Changing the Div heights in Material UI with grid layout customization

I have a project that requires me to implement material-ui. Is there a way I can adjust the width and height of the div containing the "Sign In With" text (as shown in the first image) to bring the buttons closer to the text? Transformation from this: ht ...

Automated Facebook Wall Publishing

I have successfully integrated a feature in my application where users can post status updates, photos, and URLs on their Facebook Like stream. I have also added an option for users to post directly on Facebook by including a checkbox. When the user clicks ...

Identifying text within clicked divs using identical ids

$(document).ready(function(){ $('#peoplelayer').click(function(){ $(this).fadeOut(500); var str = $(this).text(); alert(str); }); }); This is code where I use the same id "#peoplelayer" for all the divs. When on ...

Tips for efficiently retrieving all search results from a FHIR server

When utilizing the fetchAll function on an instance of an FHIR Client (specifically HAPI FHIR server), my current goal is to gather all observations with a specific LOINC code. My understanding is that a request is made to the server prompting it to gener ...

What is the best way to display the value of a PHP variable in a JavaScript pop-up window?

Here are the scripts I have. A user will input a numerical value like 123 as a parameter in the URL, and the application will retrieve that value from MySQL and display it in the textarea. For example, if you enter "example.com/index.php?id=123" in the UR ...

Customizing CSS for displayed MDBootrap components

I am currently using MDBoostrap, a styling tool similar to Bootstrap, in my React application. I have a select element that is coded like so: <div> <select id="Regions" style={errorSelect} value={this.state.userRegionId} onChange={this.handle ...

Creating a modal using JavaScript and CSS

When I click on the hello (plane geometry) as shown in the figure, a popup appears on the extreme left of the screen instead of appearing on the plane geometry box. Can someone please help me fix this issue? I have also included the code below: https://i. ...

Has Next.js incorporated a maximum cache size feature along with an invalidation algorithm like LRU?

Currently, I have a Next.js site that utilizes getServerSideProps for data fetching. However, I am interested in switching to getStaticProps and implementing incremental static regeneration (ISR) for improved performance. Currently, my memory usage is ap ...

Interactive radio button that only registers the most recent click

Homepage.jsx const Homepage = () => { const [categories, setCategories] = useState([]) const [products, setProducts] = useState([]) const [selected, setSelected] = useState("all") const getAllCategories = async() => { try{ ...

Triggering a new window on button click with Vue and Nuxt

Having an issue with a button click event in Vue that opens a PDF using window.open(). It's working well on all browsers except for Safari on MAC. Any ideas what could be causing this? Should I pass $event to the method? <div class="button-do ...

In JavaScript, the function yields a proxy rather than an object

Let's say I have an array: const arr = ['one', 'two', 'three'] Now, imagine I have a function that is designed to take an array of strings and return an array of objects: const func = (arr) => arr.map(item => ({str ...