Home> Web Front-end> Vue.js> body text

How to implement a secondary drop-down floating menu in vue.js

王林
Release: 2021-10-08 14:12:24
Original
5148 people have browsed it

Vue.js method to implement a secondary drop-down floating menu: 1. Complete the effect of a new div appearing when the mouse is hovered; 2. Realize that the personal information div does not disappear when the mouse passes the personal avatar to the personal information div; 3. Add an intermediate variable and use this variable to make judgments in the cl_person_info() method.

How to implement a secondary drop-down floating menu in vue.js

The operating environment of this article: windows10 system, vue 2.5.2, thinkpad t480 computer.

In actual development projects, we may need to implement functions similar to secondary menus. If we want to be lazy, then we can directly use the existing Element UI framework. However, this method has a big shortcoming. Only by understanding the meaning of each code can we modify the code to achieve the desired dynamic effect, so we do not recommend this method.

Some friends may ask, isn’t there jQuery? Yes, jQuery can also be implemented, but if you use jQuery to implement it, you must directly operate the DOM, and the code is more complicated.

So which method should we use? Why not use v-bind? Just do it, let’s take a look!

First complete the effect of a new div appearing when the mouse is hovering

Part of the html code is as follows:

 //@mouseover、@mouseout和 v-show="person_con" 用来控制悬浮出现和消失的效果
Copy after login

Part of the js code is as follows:

Copy after login

It's very simple. In this way, when the mouse passes over the personal avatar (person_img), the personal information person_con will appear below.

The following is the key. How to prevent the personal information div from disappearing when the mouse passes over the personal avatar to the personal information div, so that more business operations can be performed?

The natural idea is to add @mouseover and @mouseout to person_con.

Then realize that the div of personal information does not disappear when the mouse passes the personal avatar to the div of personal information

Part of the html code is as follows:

Copy after login

Part of the js code is as follows:

Copy after login

At this point, the complete function cannot be realized because the code is not perfect yet. Why? Because when the mouse moves out of the personal avatar, person_con becomes false again, which causes person_infoContinue() and cl_person_infoContinue() to have no effect. So what should we do? The natural idea is to add another intermediate variable. In the cl_person_info() method, I use this variable to make judgments.

Part of the js code is as follows:

Copy after login

At this point, the function of floating the secondary menu is completed by using simple logic to determine true and false.

Recommended learning:php training

The above is the detailed content of How to implement a secondary drop-down floating menu in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!