The bootstrap navigation bar enables the mouse to move in and expand the event, highlighting the event

Posted by midgar777 on Sat, 01 Feb 2020 00:59:32 +0100

HTML code:

<nav class="nav1 navbar navbar-default navbar-fixed-top" style="border-Radius:0px;">
    <div class="container">
    <div class="navbar-header">
        <a href="#" class="navbar-brand">logo</a>
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
                <span class="glyphicon glyphicon-menu-hamburger"></span>
            </button>
    </div>
    <div class="collapse navbar-collapse" id="navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
            <li><a href="" >home page</a></li>
            <li><a href="blogPage.action?type_id=1002">Front end </a></li>
            <li><a href="blogPage.action?type_id=1003">back-end </a></li>
            <li class="dropdown">
            <a href="blogPage.action?type_id=1003" data-toggle="dropdown" onclick="jump('1003')">
        data base<b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
                <li><a href="#">MySQL</a></li>
                <li><a href="#">SQL Server</a></li>
                <li><a href="#">Oracle</a></li>
            </ul>
            </li>
        </ul>
    </div>
    </div>
</nav>

The above drop-down menu can only be expanded by clicking navigation.
If you need to move the mouse into the navigation and expand the pull-down menu, add the following jq Code:

$(function () {
       $(".dropdown").mouseover(function () {
           $(this).addClass("open");
       });
       $(".dropdown").mouseleave(function(){
           $(this).removeClass("open");
       })
    })

Click "navigation with pull-down menu" (primary navigation) with mouse to jump:

var jump = function(type_id){
        window.location.href = "blogPage.action?type_id=" + type_id;
    }

How to highlight the navigation bar of the current page:
1. Each html/jsp has a navigation bar. Set the css of the current page navigation item to highlight
2. Multiple pages share a navigation bar (the navigation bar writes a jsp/html separately, and other pages call):
$('#navbar-collapse ul').children('li').eq(0).addClass('active');
//Child (): because the navigation bar has a drop-down menu, and the drop-down menu also has a li label. All the tags of li can be found by using child()
3. On a page, the navigation bar highlights:

   $(" ul li").click(function () {                     
       $(this).addClass("selected").siblings('li').removeClass("sele cted");
   });
   //Add a class to the clicked item and remove the class of other items

Topics: JSP MySQL SQL Oracle