The behavior of mouseover and mouseout functions becomes unpredictable in the presence of Vue JS transition components

Currently, I am developing a popup menu with the following structure:

const menuItem = {
  props: ['name', 'val'],
  data() {
    return {
      showChild: false
    }
  },
  template: /*html */ `
    <div class="nav-item" @mouseover="showChild=true" @mouseout="showChild=false">
        <span v-if="typeof val === 'string' || val instanceof String">
            <a :href="val" target="_blank" rel="noopener noreferrer">{{name}}</a>
        </span>
        <div v-else>
            {{name}}
                <ul class="popup" v-show="showChild">
                    <li v-for="(link, name) in val">
                        <a :href="link" target="_blank" rel="noopener noreferrer">{{name}}</a>
                    </li>
                </ul>
        </div>
    </div>
    `
}

const app = Vue.createApp({
  components: {
    menuItem
  },
  data() {
    return {
      menu: {
        'Home': '#',
        'Services': {
          'Software Development': 'https://www.upwork.com/signup/create-account/client_contact_freelancer?ciphertext=~0142999d8b15001517&BYOC',
          'Business Training & Frenchise': 'https://www.badabusiness.com/dd/BIMK003866',
          'Organic Marketing Training & Affiliate Program': 'https://leads-arc.web.app/'
        },
        'Our Apps': {
          'All': 'https://play.google.com/store/apps/collection/cluster?clp=igM4ChkKEzUwMDkwNjA5NzAwNjg3NTk4ODIQCBgDEhkKEzUwMDkwNjA5NzAwNjg3NTk4ODIQCBgDGAA%3D:S:ANO1ljIhW_g&gsr=CjuKAzgKGQoTNTAwOTA2MDk3MDA2ODc1OTg4MhAIGAMSGQoTNTAwOT...
        'Blogs': 'https://mayank-1513.medium.com/',
        'Contact Us': 'https://mayank-chaudhari.web.app/',
      },
    }
  }
})

app.mount('#app');
* {
  max-width: 1600px;
  margin: auto;
  transition: 0.2s all cubic-bezier(0.65, 0.05, 0.36, 1);
  color: #2c3e50;
  cursor: unset;
  box-sizing: border-box;
}

body,
html,
#app {
  margin: 0;
  padding: 0;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  max-width: 100%;
}

nav {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  
...

</script>

Everything was functioning correctly until I attempted to add a transition component and encapsulate ul.popup inside it. The issue arises as the opacity becomes 0 even when the mouse hovers over the popup menu. Below is an example illustrating this problem:

const menuItem = {
  props: ['name', 'val'],
  data() {
    return {
      showChild: false
    }
  },
  template: /*html */ `
    <div class="nav-item" @mouseover="showChild=true" @mouseout="showChild=false">
        <span v-if="typeof val === 'string' || val instanceof String">
            <a :href="val" target="_blank" rel="noopener noreferrer">{{name}}</a>
        </span>
        <div v-else>
            {{name}}
            <transition name="fade">
                <ul class="popup" v-show="showChild">
                    <li v-for="(link, name) in val">
                        <a :href="link" target="_blank" rel="noopener noreferrer">{{name}}</a>
                    </li>
                </ul>
            </transition>
        </div>
    </div>
    `

// Other Vue logic...

* {
  max-width: 1600px;
  margin: auto;
  transition: 0.2s all cubic-bezier(0.65, 0.05, 0.36, 1);
  color: #2c3e50;
  cursor: unset;
  box-sizing: border-box;
}

body,
html,
#app {
  margin: 0;
  padding: 0;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  max-width: 100%;
}

// CSS styling for navigation and popup...

.nav-item:hover .popup {
  display: inherit;
}

.fade-enter-active,
.fade-leave-active {
    transition: all .5s ease;
}

.fade-enter-from,
.fade-leave-to {
    opacity: 0;
}
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0177746441322f31353f30303f777670656671">[email protected]</a>/dist/vue.global.js"></script>

// HTML structure snippet...

How can I resolve this issue?

Answer №1

Encountered a problem with the event I was observing. Here is a detailed explanation to help others seeking a solution to a similar issue.

For more information, refer to the WC3 documentation here

The mouseover event triggers when the mouse pointer enters the div element, along with its child elements. The mouseenter event is only activated when the mouse pointer enters the div element specifically.

By simply switching from @mouseover to @mouseenter and from @mouseout to @mouseleave, the issue can be resolved.

Answer №2

Experiment with employing a combination of @mouseenter and @mouseleave

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

Incrementing numbers automatically within a JSON object while iterating through a for loop

I am struggling to figure out how to append the var i to the left side of the object declaration. This error is causing me troubles. Any assistance in resolving this issue would be greatly appreciated. If you have any alternative solutions, I am open to e ...

Exploring the various ways to incorporate diverse layer choices

I've created a small script that adds a "shades" layer to uploaded images, allowing users to save them. Currently, only one style of shades can be added. I'm looking for assistance in adding various shade options to the script. The idea is for us ...

CSS vertical alignment property

I'm facing a rather simple problem that has left me scratching my head. The vertical align property is performing correctly, but as soon as I introduce a tag after the text meant to be centered along the image, any text that follows the tag appe ...

Generating JSON Data with the Power of JavaScript and JQuery

Looking to dynamically generate a JSON Object with the specified structure: { "deleteId":[1,2,3], "pointId":[1,2,3], "update":[ { "what":"mission", "id":1, "value":"adsda" }, { ...

What is the proper way to send parameters with the "use" method in CompoundJS?

I am currently working with CompoundJS, which is an MVC framework for Express/NodeJS. The documentation mentions that to share code between controllers, I can use the publish method in controller1.js: /***controller1.js***/ function sharedFunction () {... ...

Unable to Establish Connection Between Node.js and Redis Using Docker Compose

I am trying to connect to a redis server from a docker compose network, but I keep getting a timeout error. I've attempted using localhost and other methods, but nothing seems to be working. Here's a snippet of my app.js: import express from &quo ...

Encountering an error in a React application with Redux: "Unable to access the 'state' property of undefined"

I'm currently working on a react redux application where I want to add a message to the message array in the reducer's initial state when the add message button is pressed. However, I encountered an error "TypeError: newstate1.user.id.find is not ...

Exclusive event bus dedicated to a single view

My task involves creating an event bus that functions exclusively on a single page. This is crucial due to the fact that multiple pages (views) have identical event listener names. Additionally, some components are nested within other components, making ...

The navigation icon on my website refuses to close

Hey there, I'm having some trouble creating a side navigation menu. The issue I am facing is that the menu opens without any problem, but then I can't seem to figure out how to close it using a second "onclick()" function. If you could take a lo ...

Angular RxJS: Trigger an action upon subscribing to or unsubscribing from an observable

I'm in the process of converting some Javascript events into Observables using RxJS within an Angular application built on the Ionic framework. My goal is to begin listening for events when the "client" invokes .subscribe(), and then stop listening wh ...

Creating Conditional Connections in jsPlumb

Attempting to establish connections between nodes based on specific rules, such as: The "API request" endpoint is restricted from connecting to any node except "Initiate Call". The "Failed" endpoint cannot be linked to "Play Audio", and so forth. Below ...

Arrange elements within a div using Bootstrap

I have been struggling to align items within a div tag and despite trying various methods, I have not been successful. . Here is the current structure of my code: https://i.stack.imgur.com/t9PAj.png I attempted to use flexbox, but encountered an issue ...

Adding elements dynamically with jQuery and JavaScript

Currently: The hello button is working, but when clicked, no action occurs. Query: I would like to display an alert or use console.log How could I achieve this? Here's My Code: class ArtObj { constructor(string) { this.text = string } ...

I encountered a request timeout H12 error on my app after deploying it to Heroku

Recently, I was working on a small URL shortener project as a practice exercise. It runs fine locally, but when I tried to deploy it to Heroku, I encountered an H12 request timeout error. Can someone assist me in identifying where I went wrong? My code inc ...

Newbie in JavaScript seeking help with JSON indexing: What could be causing my script using (for ... in) to fail?

Not being a seasoned Javascript coder or very familiar with JSON, my approach may seem naive. Any recommendations for better solutions are appreciated. Below is the code I've written: <!DOCTYPE html> <html> <head> <script& ...

Angular website showing only app.component.html on the frontend

I'm currently working on developing the frontend for my API and I've encountered an issue while trying to create a new component. Despite my best efforts, including setting up an app-routing.module.ts file, my application only displays the conten ...

After attempting to follow a guide, I encountered a scenario where a view was returning None because the is_ajax function was not

After diving into the world of ajax, I encountered a puzzling issue that I can't seem to crack. My hunch is that it involves the comment_id versus the blog_id. (I was following this tutorial: https://www.youtube.com/watch?v=VoWw1Y5qqt8&list=PLKILt ...

Why isn't the correct component being shown by react-router?

I have encountered an issue with my code. When I type localhost:8080 in the browser, it displays the App.js component as expected. However, upon navigating to localhost:8080/#/hello, it still shows the App.js component instead of hello.js. Interestingly, ...

Redirect data from a server's database to a local environment for testing purposes

I have been given a project at a company where I need to make some enhancements and modifications as a side project. Currently, I have an almost finished website with around 13,000 lines of code in C# and JavaScript. To avoid any mishaps on the live websit ...

CSS does not seem to support nesting list elements within other list elements

<ul> <li>One <li>two</li> </li> </ul> Attempted to target the second <li> with: li li { background: "red"; } Questioning the reason for it not functioning as expected. ...