Implement bootstrap navigation bar clickable and mouse hover display drop-down menu

Source: Internet
Author: User

When using the bootstrap navigation bar component, if your navigation bar has a drop-down menu, then the navigation of the drop-down menu will only be surfaced when clicked, and its href attribute will be invalidated, that is, the hyperlink function is lost, which is not what I want, I hope the link of the navigation bar can open its link normally, but also need drop-down menu function, start tossing ~

First solve the drop-down menu navigation bar can click the problem, the drop-down menu effect is JS implementation, analysis Bootstrap.js file discovery, bootstrap the drop down menu as a jquery plugin, in the dropdown code snippet found a key sentence:

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 to close the OK, the code is as follows:

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

The above code test is effective, the navigation bar can be clicked to solve the problem, the following to solve the mouse hover-pull menu problem, this relatively simple, with jquery mouse events can be achieved, the code is as follows:

$ (document). Ready (function () {dropdownopen ();//Call});/** * Expand the submenu with the mouse across, lest you need to click to expand */function dropdownopen () {var $ Dropdownli = $ (' Li.dropdown '); $dropdownLi. MouseOver (function () {$ (this). addclass (' Open ');}). Mouseout (function () {$ (this). Removeclass (' Open ');});

Implement bootstrap navigation bar clickable and mouse hover display drop-down menu

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.