Bootstrap navigation bar can be clicked and mouse hover display Drop-down menu implementation code _javascript Tips

Source: Internet
Author: User

When using the bootstrap navigation bar component, if your navigation bar has a drop down menu, the navigation of the Drop-down menu will only emerge from the Drop-down menu when clicked, and its href attribute will fail, that is, the hyperlink function is lost, which is not what I want, I want the navigation bar link to open its link normally, but also need to pull down the menu function, start tossing ~

First of all to solve the Pull-down menu can click the Navigation bar, the Drop-down menu effect is JS implementation, analysis Bootstrap.js file found, bootstrap the Drop-down menu written a jquery plug-in, in the dropdown code section to find the key words:

APPLY to STANDARD DROPDOWN ELEMENTS
//===================================
$ (document)
. On (' Click.bs.dropdown.data-api ', Clearmenus)
. On (' Click.bs.dropdown.data-api ', '. Dropdown form ', function (e) { E.stoppropagation ()})
. On (' Click.bs.dropdown.data-api ', toggle, Dropdown.prototype.toggle)
. On (' Keydown.bs.dropdown.data-api ', toggle + ', [Role=menu] ', Dropdown.prototype.keydown)

Find a few key code, think of the solution, as long as the Click.bs.dropdown.data-api event closed on the OK, the code is as follows:

$ (document). Ready (function () {
$ (document). Off (' Click.bs.dropdown.data-api ');
});

The above code testing is effective, navigation bar clickable problem resolution, the following solution to the mouse hover pop-up menu problem, this relatively simple, with jquery mouse events can be achieved, the code is as follows:

$ (document). Ready (function () {
dropdownopen ();//Call
});
/**
* Mouse across on the expansion of the submenu, to avoid the need to click to expand
* *
function Dropdownopen () {
var $dropdownLi = $ (' Li.dropdown ');
$dropdownLi. MouseOver (function () {
$ (this). addclass (' open ');
}). Mouseout (function () {
$ (this). Removeclass (' open ');
});

The above is a small series to introduce the bootstrap navigation bar can be clicked and mouse hover display Drop-down menu implementation code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.