Mega Menu
开发文档 and examples for Front's powerful, and responsive navigation mega menu.
How to use
Copy-paste the stylesheet <link>
into your <head>
to load the CSS.
<link rel="stylesheet" href="../assets/vendor/hs-mega-menu/dist/hs-mega-menu.min.css">
Copy-paste the following <script>
near the end of your pages under JS Implementing Plugins to enable it.
<script src="../assets/vendor/hs-mega-menu/dist/hs-mega-menu.min.js"></script>
Copy-paste the init function under JS Plugins Init., before the closing </body>
tag, to enable it.
<script>
(function() {
// INITIALIZATION OF MEGA MENU
// =======================================================
new HSMegaMenu('.js-mega-menu')
});
</script>
它是如何运作的
Here's what you need to know before getting started with the mega menu:
- Mega menu requires a wrapping
.js-mega-menu
(or any other ID or class which you can replace with) along with.navbar
class. .hs-has-mega-menu
- is a parent class that contains sub-elements within it..hs-mega-menu
- is a child class that contains a container for the mega menu.- Mega menus are responsive by default, but you can easily modify them to change that. 响应式 behavior depends on our
hs-megamenu
JavaScript plugin.
Example
<!-- Header -->
<header class="docs-navbar navbar navbar-expand-lg navbar-end navbar-light bg-white">
<div class="container">
<div class="js-mega-menu navbar-nav-wrap">
<!-- Logo -->
<a class="navbar-brand" href="../index.html" aria-label="Front">
<img class="navbar-brand-logo" src="../assets/svg/logos/logo.svg" alt="Logo">
</a>
<!-- End Logo -->
<!-- Toggle -->
<button type="button" class="navbar-toggler ms-auto" data-bs-toggle="collapse" data-bs-target="#megaMenuBasicToggler" aria-label="Toggle navigation" aria-expanded="false" aria-controls="megaMenuBasicToggler">
<span class="navbar-toggler-default">
<i class="bi-list"></i>
</span>
<span class="navbar-toggler-toggled">
<i class="bi-x"></i>
</span>
</button>
<!-- End Toggle -->
<nav class="navbar-nav-wrap-col collapse navbar-collapse" id="megaMenuBasicToggler">
<!-- Navbar -->
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<!-- Dropdown -->
<li class="hs-has-sub-menu nav-item">
<a class="hs-mega-menu-invoker nav-link dropdown-toggle" href="#" id="headerWithMegaMenuDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</a>
<!-- Mega Menu -->
<div class="hs-sub-menu dropdown-menu" aria-labelledby="headerWithMegaMenuDropdown" style="min-width: 12rem;">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<!-- Dropdown -->
<div class="hs-has-sub-menu">
<a class="hs-mega-menu-invoker dropdown-item dropdown-toggle" href="#" id="megaMenuBasicDropDown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Sub dropdown</a>
<div class="hs-sub-menu dropdown-menu" aria-labelledby="megaMenuBasicDropDown" style="min-width: 230px;">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
<!-- End Dropdown -->
</div>
<!-- End Mega Menu -->
</li>
<!-- End Dropdown -->
<!-- Nav Item -->
<li class="hs-has-mega-menu nav-item">
<a class="hs-mega-menu-invoker nav-link dropdown-toggle" href="#" id="megaMenuBasicMegaMenu" role="button" data-bs-toggle="dropdown" aria-expanded="false">Mega menu</a>
<!-- Mega Menu -->
<div class="hs-mega-menu dropdown-menu w-100" aria-labelledby="megaMenuBasicMegaMenu">
<!-- Main Content -->
<div class="navbar-dropdown-menu-inner">
<div class="row">
<div class="col-sm-6 col-md">
<span class="dropdown-header">One</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">Two</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">Three</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md">
<span class="dropdown-header">Four</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
</div>
<!-- End Row -->
</div>
<!-- End Main Content -->
</div>
<!-- End Mega Menu -->
</li>
<!-- End Nav Item -->
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<!-- End Navbar -->
</nav>
</div>
</div>
</header>
<!-- End Header -->
Columns
Adjust the size width of the mega menu, when using less columns or when the content of the container is less. Set maximum width via data-hs-mega-menu-item-options='{ "desktop": { "maxWidth": "" } }'
attribute.
<!-- Header -->
<header class="docs-navbar navbar navbar-expand-lg navbar-end navbar-light bg-white">
<div class="container">
<div class="js-mega-menu navbar-nav-wrap">
<!-- Logo -->
<a class="navbar-brand" href="../index.html" aria-label="Front">
<img class="navbar-brand-logo" src="../assets/svg/logos/logo.svg" alt="Logo">
</a>
<!-- End Logo -->
<!-- Toggle -->
<button type="button" class="navbar-toggler ms-auto" data-bs-toggle="collapse" data-bs-target="#megaMenuColumnsToggler" aria-label="Toggle navigation" aria-expanded="false" aria-controls="megaMenuColumnsToggler">
<span class="navbar-toggler-default">
<i class="bi-list"></i>
</span>
<span class="navbar-toggler-toggled">
<i class="bi-x"></i>
</span>
</button>
<!-- End Toggle -->
<nav class="navbar-nav-wrap-col collapse navbar-collapse" id="megaMenuColumnsToggler">
<!-- Navbar -->
<ul class="navbar-nav ms-auto">
<!-- Nav Item -->
<li class="hs-has-mega-menu nav-item"
data-hs-mega-menu-item-options='{
"desktop": {
"position": "right",
"maxWidth": "20rem"
}
}'>
<a class="hs-mega-menu-invoker nav-link dropdown-toggle" href="#" id="megaMenuColumnsMegaMenu20rem" role="button" data-bs-toggle="dropdown" aria-expanded="false">20rem</a>
<!-- Mega Menu -->
<div class="hs-mega-menu dropdown-menu w-100" aria-labelledby="megaMenuColumnsMegaMenu20rem">
<!-- Main Content -->
<div class="navbar-dropdown-menu-inner">
<div class="row">
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">One</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md">
<span class="dropdown-header">Two</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
</div>
<!-- End Row -->
</div>
<!-- End Main Content -->
</div>
<!-- End Mega Menu -->
</li>
<!-- End Nav Item -->
<!-- Nav Item -->
<li class="hs-has-mega-menu nav-item"
data-hs-mega-menu-item-options='{
"desktop": {
"position": "right",
"maxWidth": "30rem"
}
}'>
<a class="hs-mega-menu-invoker nav-link dropdown-toggle" href="#" id="megaMenuColumnsMegaMenu30rem" role="button" data-bs-toggle="dropdown" aria-expanded="false">30rem</a>
<!-- Mega Menu -->
<div class="hs-mega-menu dropdown-menu w-100" aria-labelledby="megaMenuColumnsMegaMenu30rem">
<!-- Main Content -->
<div class="navbar-dropdown-menu-inner">
<div class="row">
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">One</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">Two</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md">
<span class="dropdown-header">Three</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
</div>
<!-- End Row -->
</div>
<!-- End Main Content -->
</div>
<!-- End Mega Menu -->
</li>
<!-- End Nav Item -->
<!-- Nav Item -->
<li class="hs-has-mega-menu nav-item">
<a class="hs-mega-menu-invoker nav-link dropdown-toggle" href="#" id="megaMenuColumnsMegaMenuFullWidth" role="button" data-bs-toggle="dropdown" aria-expanded="false">Full width</a>
<!-- Mega Menu -->
<div class="hs-mega-menu dropdown-menu w-100" aria-labelledby="megaMenuColumnsMegaMenuFullWidth">
<!-- Main Content -->
<div class="navbar-dropdown-menu-inner">
<div class="row">
<div class="col-sm-6 col-md">
<span class="dropdown-header">One</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">Two</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">Three</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md">
<span class="dropdown-header">Four</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
</div>
<!-- End Row -->
</div>
<!-- End Main Content -->
</div>
<!-- End Mega Menu -->
</li>
<!-- End Nav Item -->
</ul>
<!-- End Navbar -->
</nav>
</div>
</div>
</header>
<!-- End Header -->
Alignment
Set "desktop": { "position": "left" }
to "left" or "right" to align the mega menu position according to that side.
<!-- Header -->
<header class="docs-navbar navbar navbar-expand-lg navbar-end navbar-light bg-white">
<div class="container">
<div class="js-mega-menu navbar-nav-wrap">
<!-- Logo -->
<a class="navbar-brand" href="../index.html" aria-label="Front">
<img class="navbar-brand-logo" src="../assets/svg/logos/logo.svg" alt="Logo">
</a>
<!-- End Logo -->
<!-- Toggle -->
<button type="button" class="navbar-toggler ms-auto" data-bs-toggle="collapse" data-bs-target="#megaMenuAlignmentToggler" aria-label="Toggle navigation" aria-expanded="false" aria-controls="megaMenuAlignmentToggler">
<span class="navbar-toggler-default">
<i class="bi-list"></i>
</span>
<span class="navbar-toggler-toggled">
<i class="bi-x"></i>
</span>
</button>
<!-- End Toggle -->
<nav class="navbar-nav-wrap-col collapse navbar-collapse" id="megaMenuAlignmentToggler">
<!-- Navbar -->
<ul class="navbar-nav ms-auto">
<!-- Nav Item -->
<li class="hs-has-mega-menu nav-item"
data-hs-mega-menu-item-options='{
"desktop": {
"maxWidth": "85%"
}
}'>
<a class="hs-mega-menu-invoker nav-link dropdown-toggle" href="#" id="megaMenuAlignmentMegaMenu20rem" role="button" data-bs-toggle="dropdown" aria-expanded="false">Left aligned</a>
<!-- Mega Menu -->
<div class="hs-mega-menu dropdown-menu w-100" aria-labelledby="megaMenuAlignmentMegaMenu20rem">
<!-- Main Content -->
<div class="navbar-dropdown-menu-inner">
<div class="row">
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">One</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md">
<span class="dropdown-header">Two</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
</div>
<!-- End Row -->
</div>
<!-- End Main Content -->
</div>
<!-- End Mega Menu -->
</li>
<!-- End Nav Item -->
<!-- Nav Item -->
<li class="hs-has-mega-menu nav-item"
data-hs-mega-menu-item-options='{
"desktop": {
"position": "right",
"maxWidth": "85%"
}
}'>
<a class="hs-mega-menu-invoker nav-link dropdown-toggle" href="#" id="megaMenuAlignmentMegaMenuRightAligned" role="button" data-bs-toggle="dropdown" aria-expanded="false">Right aligned</a>
<!-- Mega Menu -->
<div class="hs-mega-menu dropdown-menu w-100" aria-labelledby="megaMenuAlignmentMegaMenuRightAligned">
<!-- Main Content -->
<div class="navbar-dropdown-menu-inner">
<div class="row">
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">One</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">Two</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md">
<span class="dropdown-header">Three</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
</div>
<!-- End Row -->
</div>
<!-- End Main Content -->
</div>
<!-- End Mega Menu -->
</li>
<!-- End Nav Item -->
</ul>
<!-- End Navbar -->
</nav>
</div>
</div>
</header>
<!-- End Header -->
响应式
Set your collapsing breakpoint - Determines with what resolution mobile layout is enabled. Resolution Map corresponds to Bootstrap and requires the same .navbar-expand{-sm|-md|-lg|-xl}
for responsive collapsing. This example collapses the mega menu at 768
/ md
breakpoint.
<!-- Header -->
<header class="docs-navbar navbar navbar-expand-md navbar-end navbar-light bg-white">
<div class="container">
<div class="js-mega-menu-responsive navbar-nav-wrap">
<!-- Logo -->
<a class="navbar-brand" href="../index.html" aria-label="Front">
<img class="navbar-brand-logo" src="../assets/svg/logos/logo.svg" alt="Logo">
</a>
<!-- End Logo -->
<!-- Toggle -->
<button type="button" class="navbar-toggler ms-auto" data-bs-toggle="collapse" data-bs-target="#megaMenu响应式Toggler" aria-label="Toggle navigation" aria-expanded="false" aria-controls="megaMenu响应式Toggler">
<span class="navbar-toggler-default">
<i class="bi-list"></i>
</span>
<span class="navbar-toggler-toggled">
<i class="bi-x"></i>
</span>
</button>
<!-- End Toggle -->
<nav class="navbar-nav-wrap-col collapse navbar-collapse" id="megaMenu响应式Toggler">
<!-- Navbar -->
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<!-- Dropdown -->
<li class="hs-has-sub-menu nav-item">
<a class="hs-mega-menu-invoker nav-link dropdown-toggle" href="#" id="headerWithMegaMenuDropdown响应式" role="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</a>
<!-- Mega Menu -->
<div class="hs-sub-menu dropdown-menu" aria-labelledby="headerWithMegaMenuDropdown响应式" style="min-width: 12rem;">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<!-- Dropdown -->
<div class="hs-has-sub-menu">
<a class="hs-mega-menu-invoker dropdown-item dropdown-toggle" href="#" id="megaMenu响应式DropDown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Sub dropdown</a>
<div class="hs-sub-menu dropdown-menu" aria-labelledby="megaMenu响应式DropDown" style="min-width: 230px;">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
<!-- End Dropdown -->
</div>
<!-- End Mega Menu -->
</li>
<!-- End Dropdown -->
<!-- Nav Item -->
<li class="hs-has-mega-menu nav-item">
<a class="hs-mega-menu-invoker nav-link dropdown-toggle" href="#" id="megaMenu响应式MegaMenu" role="button" data-bs-toggle="dropdown" aria-expanded="false">Mega menu</a>
<!-- Mega Menu -->
<div class="hs-mega-menu dropdown-menu w-100" aria-labelledby="megaMenu响应式MegaMenu">
<!-- Main Content -->
<div class="navbar-dropdown-menu-inner">
<div class="row">
<div class="col-sm-6 col-md">
<span class="dropdown-header">One</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">Two</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md mb-3 mb-md-0">
<span class="dropdown-header">Three</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
<div class="col-sm-6 col-md">
<span class="dropdown-header">Four</span>
<a class="dropdown-item" href="#">One</a>
<a class="dropdown-item" href="#">Two</a>
<a class="dropdown-item" href="#">Three</a>
</div>
</div>
<!-- End Row -->
</div>
<!-- End Main Content -->
</div>
<!-- End Mega Menu -->
</li>
<!-- End Nav Item -->
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<!-- End Navbar -->
</nav>
</div>
</div>
</header>
<!-- End Header -->
Methods
Parameters | Description | Default value |
---|---|---|
|
Defines the event on which the menu will be displayed. Valid values are:
|
hover |
|
Direction of the menus. Valid values are:
|
horizontal |
|
Determines with what resolution mobile layout is enabled. Resolution Map corresponds to Bootstrap 4 | 'lg' |
|
Appearing effect | 'slideInUp' |
|
Disappearing effect | false |
|
Menu location during initialization | null |
|
Sets the maximum width for the dropdown menu | null |
|
If true , displays all items from right-to-left (RTL) |
false |
|
Delay of the disappearance of the menu | 300 |
|
Determines how much of the width the sidebar will occupy the dropdown list. Only works if direction: 'vertical' |
1 / 4 |
|
Determines with respect to which element the drop-down menu will be positioned. Only works if direction: 'vertical' |
$('body') |
|
Opening speed of the menu in the mobile layout | 400 |
|
Class informing that the menu is ready to work | '.hs-menu-initialized' |
|
Class informing that the menu has moved to mobile layout | '.hs-mobile-state' |
|
Class for the sub menu. The script will look for exactly this class when working | '.hs-sub-menu' |
|
Class for items that contain a sub menu. The script will look for exactly this class when working | '.hs-has-sub-menu' |
|
Class given to an invoker when opening a sub menu | '.hs-sub-menu-opened' |
|
Class for mega menu. The script will look for exactly this class when working | '.hs-mega-menu' |
|
Class for items that contain mega menus. The script will look for exactly this class when working | '.hs-has-mega-menu' |
|
Class given to an invoker when opening a mega menu | '.hs-mega-menu-opened' |
|
Timeout menu before closing in ms | null |
|
Enable animation | 'animated' |
|
Animation type on show | 'slideInUp' |
|
Animation type on hide | null |
|
Position of the menu | null |
|
Maximum width of the menu | null |