Bootstrap how to set the drop-down menu does not click, change to mouse hover direct display drop-down menu

Source: Internet
Author: User

Method One:

Actually relatively simple, only need to add a CSS settings under the hover state, the drop-down menu is set to block, specific CSS:
.nav
 > li:hover .dropdown-menu {display: block;}

But the main navigation loses the link effect!

Method Two:

Not only can solve the problem of Bootstrap mouse hover, also can let a menu restore link implementation click
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:
$(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)

It is good to close the Click.bs.dropdown.data-api event, the code is as follows:
$(document).ready(function(){
    $(document).off(‘click.bs.dropdown.data-api‘);
});

This allows the first-level menu to restore the href attribute, which functions as a hyperlink.

As for the drop-down menu suspension, the mouse is placed on the display, according to the method above the good. or use JS to achieve:
$(document).ready(function(){
    dropdownOpen();//调用
});
/**
 * 鼠标划过就展开子菜单,免得需要点击才能展开
 */
function dropdownOpen() {

    var $dropdownLi = $(‘li.dropdown‘);

    $dropdownLi.mouseover(function() {
        $(this).addClass(‘open‘);
    }).mouseout(function() {
        $(this).removeClass(‘open‘);
    });
}

Bootstrap how to set the drop-down menu does not click, change to mouse hover directly 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.