Tips for maintaining the visibility of the dynamic submenu while hovering over either the parent menu or submenu in vuejs

I'm currently working on a dynamic sidebar in vuejs and I need some assistance. The issue I'm facing is that I want the submenu to remain open when hovering over either the parent menu or the submenu itself. However, when I move the mouse away from the parent menu, the submenu disappears. I want to keep the submenu open at all times. Below is the code I have so far:

<div v-for="item in items" class="categories" >
       <p  @mouseover="onOver(item)" @mouseleave="onLeave">{{item.title}}</p>
       <div v-if="ShowSubMenu" class="subMenu">
           <div v-for="childItem in item.child" > <p class="text"> {{childItem.childTitle}}</p> </div>
           </div>

       </div>

     </div>

Vue Js:

data: {
  ShowSubMenu: false,

    items: [
    {
       title: 'name'
      },
      {
       title:'hoverMe',
       child : [
       {childTitle : 'ChildTitle1'},
        {childTitle : 'ChildTitle2'},
         {childTitle : 'ChildTitle3'},

       ] ,
       },
       { 
        title: 'name3'}
    ]
  },
  methods: {
    onOver: function(item){
        if (item.child != null) {
      this.ShowSubMenu=true;


      }
    },
    onLeave: function(){

      this.ShowSubMenu=false;



    }
  }

css:

.categories{
  background-color:red;
  width:100px;
  height:200px;
}
.subMenu{
  background-color:red;



  height:150px;
  width:150px;
  position:absolute;
  top:100px;
  left:150px;

}
.text{
  color:blue;





}

Answer №1

Try this CSS-based solution to potentially solve your issue:

https://jsfiddle.net/vugrjbn6/16/

.categories{
  background-color: red;
  width: 100px;
  height: 200px;
  position: relative;
}

.subMenu{
  display: none;
  position: absolute;
  background-color: red;
  height: 150px;
  width: 150px;
  top: 0;
  left: 100%;
}

.categories:hover .subMenu {
  display: block;
}

This method shows the submenu only when the category is hovered over. Keep in mind that the category includes both the title and the submenu. Initially, the submenu is hidden, but when you hover over the title, it appears and remains visible as long as you continue to hover over either the title or the submenu.

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

Fixed Row Feature in Visual Composer

Currently, as I work on a website in Wordpress utilizing the Visual Composer page builder, I have encountered a dilemma. I am attempting to ensure a row remains sticky at the top of the page. In an effort to achieve this, I have inserted the following CSS ...

Attempting to replicate a <textarea> to behave like a <div> element

I am currently facing an issue with my HTML and CSS code. I have tried to construct a design using a <div> but it resulted in horizontal scrolling and looked chaotic. How can I make the CSS and HTML look the same without any issues? <textarea c ...

No data found in Node.js after receiving AngularJS POST request

I've been working on sending a straightforward POST request to my server using AngularJS. The request successfully goes through and reaches the controller on the backend, but strangely, req.data is appearing as undefined. Front End Controller: funct ...

How do I use React and Material-UI to efficiently display multiple tables from a complex JSON object containing multiple arrays of data?

Trying to come up with an innovative approach to generate a unique dynamic table component that can create individual tables based on the number of arrays in a dictionary object (essentially iterating through each array and generating a table). For my sce ...

The JavaScript file fails to load when it is invoked within the <script> tag in HTML

I'm relatively new to this and I'm grappling with why my script isn't loading from the HTML. This is my primary hurdle at the moment. Next, I'm looking to obtain a list of the available COM ports and send data to a port that is ready. ...

Text within cells is not wrapping onto a new line in an HTML table

Let me show you how it currently looks: https://i.sstatic.net/OeHRg.png The maximum width of the cell is working properly, but the text is not wrapping to a new line as expected. Instead, it overflows out of the cell. Here is the CSS applied to the tabl ...

Having trouble shutting down the window using Electron and Socket io

I embarked on a chat application project using NodeJS and Socket.io, everything was running smoothly. However, when I decided to integrate my app into the Electron framework, the chat window opened but I encountered an issue with the close button not func ...

detecting user interactions with hyperlinks

Can links be intercepted in an Angular application to block specific URLs like YouTube links without adding custom attributes or elements? Is it possible to intercept all clicks on links within the scope of a particular controller's view without modi ...

Node.js/Firebase function to delete an item from a JSON object and update the existing items

I'm currently facing a challenge with updating a JSON file in Firebase after deleting an item using the .delete() function. Here is the original JSON data before deletion: "data": [ { "position": "3", ...

Guide to transferring existing Mongoose Schema information to updated Mongoose Schema Data

In the schema I was using previously with Mongoose, it looked like this: social:{ instagram: String, facebook: String, whatsapp: String, } Now, my updated Mongoose Schema is structured differently: social:{ instagram: { dat ...

Design a PHP tool for generating custom CSS frameworks

After attempting to create a CSS frame generator similar to this one, I stumbled upon a solution that works well with one exception. PHP Code: <?php function print_css($parentTag, $prefix, &$dup_checker) { if ($parentTag->nodeName == &apos ...

Issues with dependencies in npx create react app

After initiating a new react project with npx create-react-app client, I have encountered an issue where the react-scripts command is not found, preventing me from running the start script. Is there a way to resolve this problem? Furthermore, when attempt ...

"Why does adding a new span create space between it and the previous ones, and what can be done to prevent this from

Essentially, it creates the equation "a + b = c". However, I need to create "a + b = c" instead. HTML: <div class="container"> <span id="b__value">+b</span> <span id="c__value">=c</span> &l ...

Spinning 3D Grid in Global Coordinates - Using THREE.js

I'm struggling with rotating an object in my project. I am currently utilizing THREE.Shape to define a custom shape. After creating the shape, I convert it into a Mesh and set its position to: buildingMesh.position.set(-70, -300, levelY); However, d ...

The import component path in Angular 4/TypeScript is not being recognized, even though it appears to be valid and functional

I'm currently working on building a router component using Angular and TypeScript. Check out my project structure below: https://i.stack.imgur.com/h2Y9k.png Let's delve into the landingPageComponent. From the image, you can see that the path ...

Tips for making a dynamic active button using javascript

I'm trying to create a toggle button with eight buttons. When seven out of the toggle buttons are clicked, it should toggle between two classes and change its CSS styles. If the daily button is clicked, it should toggle the styles of the other seven b ...

Position the site at the center of the screen for perfect alignment

As I work on building a website, I am striving to achieve perfect center alignment both horizontally and vertically on the screen. However, despite my efforts, I have only managed to center it horizontally so far. After thorough research, the solutions I ...

Tips for ensuring that the Nuxt child component does not render until the asyncData call has completed

When working with a form that consists of two components – a parent (responsible for calling asyncData and passing data as props to the child) and a child (which represents the actual form) – I encountered an issue. I found that I can successfully fetc ...

Combining the powers of Nextjs and Vue

Currently utilizing Vue.js, I am now looking to leverage the Next.js framework for its SEO capabilities, server-side rendering features, and other advantages. While I do have some experience with React, my primary focus is on mastering Vue.js. Is it poss ...

Leveraging Jest for mocking "import * as" operations

Is there a way to effectively mock this specific type of import using jest? import * as some from 'some-package'; ...