[Bootstrap] Triggering dropdown-toggle on Mouse Hover in Bootstrap

Using the bootstrap-hover-dropdown Plugin

1. Download bootstrap-hover-dropdown

Download link: http://www.bootcdn.cn/bootstrap-hover-dropdown/

Of course, you can also use the CDN version directly.

2. Include bootstrap-hover-dropdown.js

In your HTML file, make sure to include bootstrap-hover-dropdown.js. Typically, you can place it in a <script> tag at the bottom of the page:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bootstrap Hover Dropdown Example</title>
    <!-- Include Bootstrap CSS -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <!-- Your content -->

    <!-- Include jQuery -->
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <!-- Include Bootstrap JS -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    <!-- Include bootstrap-hover-dropdown.js -->
    <script src="path/to/bootstrap-hover-dropdown.js"></script>
</body>
</html>

3. Modify the Dropdown in HTML

Find the element with the dropdown-toggle class in your HTML file and modify it as follows:

1
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>

Change it to:

1
<a href="#" class="dropdown-toggle" data-hover="dropdown" data-close-others="true">Dropdown</a>

You can also add a parameter data-delay="1000", which sets the delay before the dropdown disappears (default is 500 milliseconds). For example:

1
<a href="#" class="dropdown-toggle" data-hover="dropdown" data-close-others="true" data-delay="1000">Dropdown</a>

4. Removing the Delay

If you want to completely remove the delay, you can directly modify the configuration in the bootstrap-hover-dropdown.js file, changing delay: 500 to delay: 0.

Find and modify the following code:

1
delay: 500

Change it to:

1
delay: 0

This will remove the dropdown menu delay.