What methods can be used to incorporate animation when the display attribute transitions to none?

Is there a way to add animation in a Vue app when replacing elements? I would like the transition from, for example, clicking on a div with 'Num 1' to the divs with class 'showing' not disappear abruptly but smoothly, such as moving to the side or another method. Can this be achieved by changing classes, or is there a better way to achieve the desired smoothness?

<template>
  <section class="maps" id="maps" style="">
  
          <div class="showing" :class="{'showingopen':opened1||opened2||opened3||opened4||opened5||opened6||opened7}">
              
              <div class="title py-2 px-2" @click="openpav(1)" :class="{'pav1':opened1}">Num 1</div>
              <div class="title p-2" @click="openpav(2)"  :class="{'pav2':opened2}" >Num 2</div>
              <div class="title p-2" @click="openpav(3)" :class="{'pav3':opened3}">Num 3</div>
              </div>

              <div class="pav1" :class="{'pavopen1':opened1}">
                <div>
                  kldmf
                </div>
                <div>
                  klsfdmn
                </div>  
              </div>
</section>
</template>

<script>

export default {
  name: "maps",
  data() {
    return {
      opened1:false,
      opened2:false,
      opened3:false,}
}
mounted() {
   
  methods: {
openpav(i){
      if (i==1){
        this.opened1 = true
        this.opened2 = false
        this.opened3 = false
      }
      if (i==2){
        this.opened1 = false
        this.opened2 = true
        this.opened3 = false
      }
      if (i==3){
        this.opened1 = false
        this.opened2 = false
        this.opened3 = true
      }

    }
}
}

<style scoped>
.pav1{
  display: none;
}

.pavopen1{
  display: block;
}
.showing{
  display: flex ;
  flex-direction: column;
}

.showingopen{
  display: none;
}

Answer №1

If you're trying to determine when an animation has finished, using setInterval is not necessary. You can simply listen for the event animationend.

Take a look at this straightforward example where a div fades out over 10 seconds and then its display property is set to none.

const div = document.querySelector('div');
div.addEventListener('animationend', function () {div.style.display='none';animation=''; });
div {
  animation: fade 10s 1;
  animation-fill-mode: forwards;
  }
@keyframes fade {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
<div>hello</div>

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

Tips for effectively changing Observable data into an Array

I am currently attempting to transform an Observable into an Array in order to loop through the Array in HTML using ngFor. The Typescript code I have now is causing some issues. When I check the testArray Array in the console, it shows up as undefined. it ...

Unable to modify page property status through the Notion API

I've been attempting to use the Notion JS-sdk to update a page's status using their API. However, I've run into some issues that I can't seem to resolve. Updating the status requires modifying the properties object, but no matter what ...

Placement of navigation bar on top of picture

Creating a gaming website and encountering challenges with text alignment. The goal is to have the navbar text positioned on top of a customized navbar background. Current appearance navbar example <!DOCTYPE html> <html> <head> ...

Having issues with the addClass() method in JavaScript not functioning properly on hover

Coding Challenge <ul class="navBarExtended"> <li><a href="#">Link</a></li> </ul> Styling Solution .onHover{ text-decoration: underline; } Interactive Scripting $("ul.navBarExtended li a").hover( function() ...

Tips for achieving vertically centralized components with uniform height columns in Bootstrap 4

I tried implementing the solution provided in this question: Bootstrap 4 vertical center - equal height cards However, I am still facing an issue. Despite applying the suggested code: <div class="cycle-des h-100 justify-content-center">Product Cycl ...

Instructions on exporting binary data to a PNG file using nodejs

How can I convert a binary nodejs Buffer object containing bitmap information into an image and save it to a file? Edit: I attempted using the filesystem package as suggested by @herchu, but when I tried the following code: let robot = require("robotjs" ...

What is the purpose of implementing asynchronous loading for JavaScript in my webpack setup?

I am facing difficulties with handling unusual codes. I am trying to add some query parameters using $.ajaxPrefilter in all jQuery ajax requests. I came across the following code snippet which seems to ensure synchronous loading order, but in my entry.js ...

The object's key values were unexpectedly empty despite containing data

There's an issue with my object - it initially gets key values, but then suddenly loses them all. All the key values become empty and a message appears in the console for the object: "this value was evaluated upon first expanding. it may have ch ...

React hook dom and material-ui FormControlLabel are causing a checkbox input to return an empty string instead of the expected true/false value

I am currently working on displaying the values returned from a form, specifically focusing on the Checkbox section. <FormControlLabel control={<Checkbox {...register('remember')} name="remember" color="primary" defaultV ...

Utilizing AJAX to dynamically populate a dropdown menu with data from a SQL

Having recently delved into the world of ajax, I have a basic understanding of how it works. I've implemented a registration form that dynamically updates the fields for "country, city, and area" using ajax to fetch data from a database. The PHP code ...

Is there a way to switch the main image by clicking on different thumbnails in a sidebar using javascript/jQuery

Currently on my page, I have a large plot created with jqplot along with a sidebar containing several smaller plots. I am trying to find a way to dynamically change the large plot based on which of the smaller plots the user clicks on, without needing to ...

The best way to close a swipeable drawer from a different class

I'm feeling a bit puzzled by the explanation of SwipeableDrawer on the Material-ui website. Here's the setup I have: there's a Component called 'Sidebar' that opens a SwipeableDrawer when a user clicks a button on the appbar or swi ...

The MUI Grid design features information displayed on the left side, accompanied by an image placed directly to the right

In the React MUI V5 sample code below, I am creating a profile page layout with details of a person displayed on the left side of the page in label/value format. My question is how to position an "IMAGE" entry (assume it's a 300px x 300px profile ima ...

Is there a method to delay the loading of a webpage until an image has fully loaded (preloading)?

How can I ensure that an image used in a preloader is loaded before the other contents on my website? <div class="overlay" id="mainoverlay"> <div class="preloader" id="preloader"> <img src="images/logo128.png" id="logo-p ...

Unique column arrangement specifically designed for the initial row within the loop

My webpage features a layout that showcases 4 images on each row. However, I am looking to create a special first row with a unique column configuration compared to the rest of the rows. Here is an example of what I have in mind: https://i.sstatic.net/Rs ...

What could be causing the lack of population in ngRepeat?

In my angular application, I encountered an issue with ngRepeat not populating, even though the connected collection contains the correct data. The process involves sending an http get request to a node server to retrieve data, iterating over the server&a ...

Utilizing React Selector: Propagating the onChange Event Up Two Components

Struggling to pass an onChange event from React selector through two components back up to the parent App. The issue is that e.target.value is coming back as undefined, indicating that the event might not be returning properly. Can someone pinpoint what&ap ...

What are some ways to implement AJAX with input from the user?

I'm currently working on a project to create a basic web page that will make use of AJAX for displaying results. Within main.py, I have a dictionary of words: words = { 'a': True, 'aah': True, 'aahed': True, ...

Styling a half circle in React Native

Despite my efforts, I have not been able to find anything quite like this: example Could anyone provide guidance on implementing this with react? ...

How can I incorporate dynamic fields into a Typescript type/interface?

In my Typescript interface, I have a predefined set of fields like this: export interface Data { date_created: string; stamp: string; } let myData: Data; But now I need to incorporate "dynamic" fields that can be determined only at runtime. This me ...