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

Updating button appearance when clicked using Vue.js and Tailwind CSS

As part of my learning journey, I have expanded this code to enhance my frontend skills. While I am aware that the code can be significantly shortened, I am focused on learning and broadening my experience in frontend development. The code below functions ...

Arrange the labels and input fields within nested elements in a synchronized manner

My data is structured semantically as shown below: <div class="inputs"> <div class="top"> <h4>Top</h4> <label for="top-1">Label 1</label> <input id="top- ...

Renew the Look of Dynamic HTML with Updated Styles

In the middle of my website, there is a console that contains links to dynamically update its content using javascript. Everything works smoothly, but the new HTML added dynamically does not have any styling applied to it. Is there a way to refresh the CS ...

What is causing my navbar's 'ol' element to have a wider width than the

Hello, I have a navigation bar with a dropdown menu using ol. However, when I hover over the list items, the width of the list exceeds that of the ol element. I believe this is due to the white-space: nowrap CSS property, but I want the text in the dropdow ...

Place the element at the bottom of the row above

I'm utilizing Angular to retrieve a list of items from the server and exhibit them on the page using: <div class="col-sm-6 col-md-4" ng-repeat="activity in activities"> <img ng-src="[[ act.icon ]]" height="100" alt=""> <h3>[ ...

Getting two child elements to be perfectly centered vertically

I have encountered a similar issue to many others, but despite trying various solutions, I can't seem to identify where I am going wrong. My parent element is supposed to display 3 blocks of information across the screen, each consisting of a large ic ...

When I update URLs in Django, my CSS breaks down

Recently, I encountered an issue on my website and found a solution by creating two separate HTML pages. However, when I modified the urls.py to differentiate the URLs for these pages, the CSS stopped working. Below is my code snippet and a detailed explan ...

Ways to dynamically modify the CSS attributes of a webpage during the page load event

I'm looking to incorporate the background:rgba(226, 93, 141, 0.76) attribute into the body:after psuedo-element once my page has finished loading. Below is my HTML and CSS code: <style runat="server" id="myStyle" > body:after{ position:fix ...

Calculator built with HTML, CSS, and JavaScript

Hi there, I'm experiencing some issues with my calculator. The buttons seem to be working fine and lining up correctly, but for some reason, nothing is showing up on the monitor or getting calculated when I press the buttons. Here's the code that ...

Positioning the div to align perfectly alongside the list items

My current objective involves dynamically creating div elements and populating them with items. A working demo of my progress can be found by following this link. The issue at hand is that the newly created div does not appear in the desired location, but ...

Get rid of the margins on your Wordpress theme

Currently, my Wordpress site is using the Tesseract theme which can be found at (http:// instantiwebs . com) I am interested in removing the left/right margins on all elements, similar to what has been done on this website: . Interestingly enough, they al ...

Issue with CSS background images not resizing properly on iPad and iPhone devices

While my site's background image resizes nicely in Chrome and Safari using background-size: cover, I encountered an issue when testing it on an iPad or iPhone. The CSS background image appears to be extremely zoomed in, resulting in a horrible appeara ...

Storing a date in MySQL using Vue.js and Node.js

My current tech stack consists of nodejs and express.js for the backend, vuejs for the frontend, and mysql as the database. I am facing an issue where I cannot send a date retrieved from localStorage to my mysql database. Whenever I try to send the date, ...

Generate HTML content based on the permissions from a REST API

I have a frontend that renders based on user permissions from a REST API. These permissions could include deleting users, creating users, adding users to workflows, and more. Most of these permissions are managed by an administrator. So my question is: H ...

What is the method for styling the third list item in a CSS hierarchy?

I'm struggling to understand the hierarchy in CSS for creating this specific layout. I've searched for explanations, but haven't found a clear one that breaks down how each level works. This is my first time working with CSS so it's bee ...

When running "npm run build" in Vue.js Vue-cli, the CSS is compiled to set the image opacity to 1%

Executing npm run serve results in everything working correctly. After running npm run build, no errors are reported. Upon viewing the website, I noticed that the images in the gallery section were not visible. Upon inspecting the element, I found that t ...

Is it possible for users to circumvent limitations on specific routes or pages in a Vue.js application by exploiting the fact that all the code is processed on the client

When developing a single page application utilizing technologies like Firebase, do API keys remain hidden from users since all code is executed on the client side? Additionally, given that users are limited to specific routes or pages based on conditions ...

Is it possible to alter the value of a global variable within a function and switch its value based on a local variable?

Currently, I am facing an issue with changing the value of a global variable dynamically from a function. The variable has a global scope and is also present in the same function as a local variable. However, despite my efforts, I am unable to successful ...

What is the top choice for creating a shallow copy of an array

While delving into the vue source code today, I stumbled upon a method of writing that left me puzzled. view source const deduped = [...new Set(pendingPostFlushCbs)] My initial thought is that it is a shallow copy of the array. But why is there a need t ...

The vuetify-loader fails to automatically initiate my variables during bootstrapping

After setting up my project with vue-cli and installing vuetify through vue-cli, I decided to create a directory named sass within the src folder, containing a variables.scss file. According to the documentation (https://vuetifyjs.com/en/features/sass-var ...