Documentation
jqxNavBar is a small widget which is built from UL and LI tags. It can be used for creating responsive horizontal/vertical layouts or simple navigation menus.
jqwidgets-scripts4 scripts, listed below
Load the styles and the NavBar's scripts - from the jsDelivr CDN as here, or from node_modules/jqwidgets-scripts/jqwidgets/ after npm install jqwidgets-scripts. jQuery is optional: jqxcore.js works on its own.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/styles/jqx.base.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/styles/jqx.fluent.css">
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxcore.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxnavbar.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxlistbox.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqwidgets-scripts@27/jqwidgets/jqxscrollbar.js"></script>
Then create it on an element with $('#navBar').jqxNavBar({ … }). The live demos show every option with its source code; the guide below explains them.
Every UI widget from jQWidgets toolkit needs its JavaScript files to be included in order to work properly.
The first step is to create html page and add links to the javascript files and css dependencies to your project. The jqxNavBar widget requires the following files:
<head>
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" />
<script src="../../jqwidgets/jqxcore.js"></script>
<script src="../../jqwidgets/jqxnavbar.js"></script>
</head>The next step is to create an UL with LI tags within the body of the html document.
<div id="navBar">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>The last step is to initialize the widget by adding the following script to the html document:
<script>
$(document).ready(function () {
$("#navBar").jqxNavBar({ height: 40, selectedItem: 0 });
});
</script>To call a function(method), you need to pass the method name and parameters(if any) in the jqxNavBar’s constructor.
$("#navBar").jqxNavBar('open');To set a property(option), you need to pass the property name and value(s) in the jqxNavBar's constructor.
$("#navBar").jqxNavBar({ selectedItem: 1 });To get a property(option), you need to pass the property name to the jqxNavBar's constructor.
const selectedItem = $("#navBar").jqxNavBar('selectedItem');To bind to an event of a UI widget, you can use basic jQuery syntax. Let’s suppose that you want to know when the selected item is changed.
// bind to 'change' event.
$('#navBar').on('change', function (event) {
});
<!DOCTYPE html>
<html lang="en">
<head>
<title id="Description">jQuery NavBar</title>
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" />
<script src="../../jqwidgets/jqxcore.js"></script>
<script src="../../jqwidgets/jqxnavbar.js"></script>
<script>
$(document).ready(function () {
$("#navBar").jqxNavBar({ height: 40, selectedItem: 0 });
});
</script>
</head>
<body>
<div id="navBar">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</body>
</html>