transitioning backwards upon the removal and addition of classes in vue

Currently, I am working on creating a help button that triggers a help-dialogue box with some animations when clicked.

This is the template I am using:

<template>
  <div class="help">
    <button v-if="theme" class="help-icon" @click="helpOpen">?</button>
    <section class="help-dialogue-box"
      :class="{ 'help-open': isHelpOpen, 'help-close': isHelpOpen === false }">
      
    </section>
  </div>
</template>

Here is the CSS section:

.help-dialogue-box{
  position: absolute;
  transform: translateX(50%) scale(0, 0);
  top: 50%;
  right: 50%;
  background-color: honeydew;
  width: 75vw;
  height: 90vh;
  border-radius: 500px;
  pointer-events: none;
  overflow: hidden;
}

.help-open{
  animation-name: expand;
  animation-duration: 2s;
  animation-direction: normal;
  animation-fill-mode: forwards;
  pointer-events: all;
}

.help-close{
  animation-name: expand;
  animation-duration: 2s;
  animation-direction: reverse;
  animation-fill-mode: forwards;
}

@keyframes expand{
  0%{
    transform: translateX(50%) scale(0, 0);
    border-radius: 500px;
  }

  50%{
    transform: translateX(50%) scale(0.6, 0.6);
  }

  100%{
    transform: translateX(50%) scale(1, 1);
    border-radius: 5px;
  }
}

If necessary, here is the script part as well:

data(){
    return {
      isHelpOpen: null
    }
  }

  methods: {
    helpOpen(){
      this.isHelpOpen = !this.isHelpOpen;
    }
  }

While the animation works perfectly when adding the help-open class, there seems to be an issue when removing it and adding the help-close class. The element disappears without any animation. I have tried manually adding and removing classes one by one but it didn't solve the problem.

Is there something wrong in my approach?

My goal is for the element to animate in reverse direction when removing the help-open class.

Answer №1

Vue offers a built-in transition feature for easy implementation of transitions. There are predefined modes that can be used in conjunction with transitions. If you require custom transitions, Vue allows the use of custom transition classes.

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

The functionality of scrolling ceases to work once the bootstrap modal is closed

I am utilizing Bootstrap v3.1.1 to showcase a modal popup on one of my web pages. The following code shows how I have implemented it. <!--Start show add student popup here --> <div class="modal fade" id="add-student" tabindex="-1" role="dialog" a ...

Image background is not showing up in the input field

It seems like I've hit a roadblock with this issue. Despite my best efforts, I can't seem to find a solution. You can view the problem LIVE HERE. The banner's two input boxes should have background images displayed, but they are not showin ...

Experiencing npm for the first time and seeing an error message that says Syntax

Update: I have made some changes to my package.json based on the progress of my research, and it seems to be related to babel. I am continuing to investigate. However, I would like to update the package.json that I will use moving forward and try to find t ...

Ext.ux.TDGi.iconMgr is a cutting-edge plugin designed specifically for the latest version of

Has anyone successfully migrated the Ext.ux.TDGi.iconMgr plugin to ExtJS 4? (http://tdg-i.com/44/extuxtdgiiconmgr...-icons-and-css) ...

Troubleshooting: CSS Animation Not Showing up on Screen

When I was attempting to create a JavaScript game in HTML, I encountered a problem. Despite ensuring that the syntax was correct and conducting some research online, the animation refused to display. No matter how many times I tried, it just would not work ...

Tips for positioning an inner div within an outer div

Code Snippet: <div style="width: 300px; position: absolute; right: 25%; top: 5%; -webkit-box-shadow: 2px 4px 40px 0px rgba(0,0,0,0.75); -moz-box-shadow: 2px 4px 40px 0px rgba(0,0,0,0.75);box-shadow: 2px 4px 40px 0px rgba(0,0,0,0.75);"> <secti ...

CSS - Implementing responsive design to ensure optimal viewing experience on all devices

Card Matching Game Project Codepen Check out my CSS here, and find the rest of the code on Codepen since it's quite lengthy. const cards = document.querySelectorAll('.memory-card'); let hasFlippedCard = false; let lockBoard = false; let ...

Developing a progress bar with jQuery and Cascading Style Sheets (

Below is the code I'm currently using: <progress id="amount" value="0" max="100"></progress> Here is the JavaScript snippet I have implemented: <script> for (var i = 0; i < 240; i++) { setTimeout(function () { // this repre ...

Change the color of the text in a shiny dashboard

While exploring shiny dashboard, I came across this link that explains how to modify colors in the sidebar and header. However, I'm struggling to change the font color for sidebar items. The default white font color becomes unreadable when using light ...

Tips for adjusting the initial scale to ensure your mobile website fits perfectly on the screen

I'm trying to figure out the best way to adjust the 'initial-scale' so that my website's width fits perfectly on any device screen when first loaded. Check out my website here: While it looks fine on regular browsers, I had some issue ...

VueJS - Identical keys found while iterating through md-table items

I am attempting to display a material table for a database object that repeats its IDs. <md-table v-model="data"> <md-table-toolbar> <div class="md-toolbar-section-start"> <h1 class="md-t ...

How can I display a spinner/loader gif when the page loads using Vue?

When it comes to loading components on a webpage, jquery has the options of $( document ).ready() and onload. But in Vue, how can we achieve the same effect? For example, when a user clicks our page, how can we display a spinner until all contents are load ...

Achieve uniform height for two elements using Material UI

Here is the code snippet I have: <div className="center"> <TextField variant="outlined" className="manualUserFollowTxt" required id="manualUserFollowTxt" label="Username" name="username" autoComplete="username" a ...

The attempted download of the repository vuetifyjs/webpack was unsuccessful due to a Response code 404, indicating that the resource

I am currently attempting to install the Vuetify template found on vuetifyjs.com My command was: vue init vuetifyjs/webpack ad-project The response I received was: vue-cli · Failed to download repo vuetifyjs/webpack: Response code 404 (Not Found) Wh ...

Tips on how to prevent certain classes from being impacted by a hue-rotate filter applied to all elements on a webpage

I am currently in the process of adding a feature that allows users to choose between a dark or light theme, as well as select a specific theme color for the app. The implementation involves using CSS filters such as invert(1) for the dark theme and hue-ro ...

How to temporarily disable CSS hover effects

I have a menu with some links <ul id="nav"> <li> <a href="#">Project</a> <div class="subs"> <div> <ul> <li> <h3>Save</h3> <ul> <li> <a i ...

Guide on navigating to a specific step within a wizard using Vue and TypeScript

In this wizard, there are 6 steps. The last step includes a button that redirects the user back to step 4 when clicked. The user must then complete steps 5 and 6 in order to finish the wizard. step6.ts <router-link to="/stepFour" ...

When utilizing VueJs, it's not possible to retrieve a data property from within a function

I am encountering a challenge when trying to access the data property within the function. Despite my efforts, I seem to be missing something crucial and unable to pinpoint what it is. Here is my class: export default { name: "Contact", component ...

What are some ways I can ensure my webpage remains consistent and user-friendly when scrolling, rather than appearing distorted and jumbled?

Is there a way to automatically scroll my page when the window is at a small height, instead of adjusting it to the height by squeezing it? I've tried using overflow in different ways, but haven't been successful in getting the entire page to scr ...

Styling a Form Submission with CSS

I am currently working on a website that contains the following PHP code: echo "<form action='choice.php' method='post'>"; echo "<input type='submit' name='choice' value='left' /> "; As I am i ...