Vue transition not functioning properly when hovering over text for changes

When you hover over the circular region on the website, the text and description in the red box will change.

To add a fade animation effect when the text changes, I attempted to use <transition> as per the documentation provided in this link.

Unfortunately, the transition effect is not working as expected.

App.vue

<template>
  <div id="app">
    <div
      v-for="opt in options"
      :key="opt.id"
      class="item"
      @mouseover="changeCurrentOption(opt.id)"
    >
      {{ opt.name }}
    </div>
    <div class="text">
      <transition name="component-fade" mode="out-in">
        <div class="title">{{ options[currentOption - 1].name }}</div>
      </transition>
      <transition name="component-fade" mode="out-in">
        <div class="description">
          {{ options[currentOption - 1].description }}
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      options: [
        {
          id: 1,
          name: "Cat",
          description:
            "Lorem Ipsum is simply dummy text of... // (Continues similarly...)
        },
        // Additional data for Dog may be found here...
      ],
      currentOption: 1,
    };
  },
  methods: {
    changeCurrentOption(id) {
      this.currentOption = id;
    },
  },
};
</script>

<style lang="scss">
#app {
  text-align: center;
  margin-top: 60px;
  .item {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    border: 1px solid black;
    margin-bottom: 1rem;
  }
  .text {
    border: 1px solid red;
  }
}
</style>

https://i.sstatic.net/Osh90.png

CodeSandbox:
https://codesandbox.io/s/hardcore-montalcini-dcyi2?file=/src/App.vue

Answer №1

To ensure smooth transitions, it is important to use the correct syntax for transition. For more information on this, refer to the Vue.js documentation: Enter/Leave & List Transitions

I have made corrections to your code below:

<template>
  <div id="app">
    <div
      v-for="opt in options"
      :key="opt.id"
      class="item"
      @mouseover="changeCurrentOption(opt.id)"
      @mouseleave="mouseleaveHandel"
    >
      {{ opt.name }}
    </div>
    <div class="text">
      <transition name="fade" mode="out-in">
        <div v-if="descriptionVisibale">
          <div class="title">{{ options[currentOption - 1].name }}</div>

          <div class="description">
            {{ options[currentOption - 1].description }}
          </div>
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      descriptionVisibale: true,
      options: [
        {
          id: 1,
          name: "Cat",
          description:
            "Lorem Ipsum is simply dummy text of the printing and typesetting industry...."
        },
        {
          id: 2,
          name: "Dog",
          description:
            "It is a long established fact that a reader will be distracted by the readable content..."
        }
      ],
      currentOption: 1
    };
  },
  methods: {
    changeCurrentOption(id) {
      if (this.currentOption !== id) {
        this.currentOption = id;
        this.descriptionVisibale = false;
        setTimeout(() => {
          this.descriptionVisibale = true;
        }, 1000);
      }
    },
    mouseleaveHandel() {
      this.descriptionVisibale = true;
    }
  }
};
</script>

<style lang="scss">
#app {
  text-align: center;
  margin-top: 60px;
  .item {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    border: 1px solid black;
    margin-bottom: 1rem;
  }
  .text {
    border: 1px solid red;
    min-height: 5rem;
    padding: 1rem;
  }
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
</style>

To resolve any remaining issues, you may need to utilize `setTimeout()` as shown here: setTimeout()

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

Creating Sleek Rounded Corners with Pure CSS in Older Versions of Internet Explorer (Compatible with jQuery)

Looking for a seamless solution to render rounded corners on browsers that do not support CSS3 without the delay typically seen with JQuery plugins. The use of .htc files with www.css3pie.com seems like the best option so far, but there is still a delay c ...

Modifying the cursor presentation in the Atom editor

Hey there, I'm curious if there is a method to customize the caret style in Atom similar to how it's done in Sublime Text 3. In Sublime Text 3, you can change the caret style using this JSON setting: "caret_style": "phase" Is there a comparable ...

What signals to Angular that $httpBackend is substituting $http during the testing of AngularJS?

My factory, called myFactory, has a dependency on $http. When writing tests for this, I needed to mock this dependency. After some research, I discovered that I could accomplish this using $httpBackend. Implementing the code below successfully achieved t ...

How to position multiple CSS background images effectively?

Greetings all! I'm seeking advice on how to add a background image to the right of the description and left of the first post column. Any tips on proper placement? Appreciate any help :) ...

Establishing a standard flatiron-director route (within the element) using the polymer core-pages component

This particular query is closely linked with issues surrounding the usage of flatiron-director/core-pages SPA in conjunction with route-specific JavaScript functions and default routes. While the solution proposed may be effective, my limited expertise in ...

Link various data to various text boxes using a common ngModel property in Angular 8

In my project, I am working on creating a time-picker that will open when the user focuses on a text-box. The challenge I'm encountering is that although there are multiple text-boxes on a single page, binding the selected value from the time-picker u ...

Spacing between table cells is only applied to the first row and footer

In an attempt to add spacing between the first row, second row, and footer of a table, I have experimented with cell spacing combined with border-collapse. However, the spacing is being applied all over the table instead of in specific areas. I am utilizin ...

Trigger click functions sequentially to display elements after specific actions are taken

Is there a way to make jQuery listen for clicks only at specific times? It seems that when I add event listeners, like $("#box").click(function(){, they are executing before the code above them finishes running. Let's say I have two boxes that should ...

Using orchestrate.js for local passport.js authentication

I need assistance finding a tutorial or resources for setting up local passport.js authentication with Orchestrate as the user storage. Most of the resources I have come across are based on MongoDB, but our project requires us to use Orchestrate. Any advic ...

Send multipart form data to a different server via pipe

I need assistance with handling a POST request on my Node Express server for uploading images through multipart form data. Currently, my Express app is set up to use body parser which does not support multipart bodies and suggests using alternative librari ...

The processing indicator fails to function properly when trying to refresh a jQuery datatable

I am currently customizing the loading indicator for the datatable using a spinner called startLoadGlobal(SPINNER_DATA_TABLE_FINANCEIRO_CARREGAR_REGISTROS) in jQuery. It works correctly when I initially load the datatable, however, when I reload it, the sp ...

Show the current server time on the client side using Meteor

Is there a more efficient way to display the server's time as a running clock (h:m:s) on the client using Meteor? Traditional JavaScript/PHP methods involve fetching the server time periodically and calculating the time difference with the client. Bu ...

adding a variable to the value of an input field using the val() method

Here is a code snippet that appends the text 'text goes here' to an input value: $('#someid').val($('#someid').val() + 'text goes here'); I attempted to use a variable in a similar way, but it didn't work as e ...

Dividing HTML and JavaScript using Vue

Is there a way to separate HTML from data/methods in VueJS to avoid having one long file with both? I tried moving the contents of my <script> section into a new file called "methods.js" and importing it using: <script src="methods.js"> Note ...

Tips for creating responsive Math Latex

Check out this link to my website page. Also, take a look at this other link. While using Bootstrap, I've noticed that all content is responsive except for the equations in the first link and the Matrix multiplication example in the second link towar ...

Why might a responsive website automatically switch to mobile view?

My website has a responsive grid system that utilizes media queries with breakpoints. However, I am encountering an issue on IE8 where the "mobile version" of the site is being displayed as the default view even when the screen size is set to what should b ...

"Error message pops up indicating the dispatcher is missing while using npm link with a local project

Currently, I am working on a React component library that I want to integrate into a local project for testing purposes. My initial approach was to use npm link to connect the component library with my local project. However, during this process, I encount ...

It appears that the React MUI Grid is causing the page or its container to experience overflow issues

I'm utilizing Grid to maintain the organization of the entire page, but I keep encountering an overflow issue when adding multiple Grid items. This results in the scrollbar appearing even though the container size remains the same. Dashboard.tsx is pa ...

Utilizing arrays in Expressjs: Best practices for passing and utilizing client-side arrays

Here is the structure of an object I am dealing with: editinvite: { _id: '', title: '', codes_list: [] } The issue I am facing is that I am unable to access the codes_list property in my NodeJS application. It appears as 'u ...

Revising HTML content when Angular array is modified

I have a code snippet below where I am updating the value of an object in the first item of an array. However, I'm struggling to find a way to "refresh" the HTML view so that the changes are immediately reflected on the browser. var dataArr ...