


Bootstrap Ace template worth sharing to achieve menu and tab page effects_javascript skills
This article shares the menu style and iframe-based Tab page effect using the Ace template in the project.
1. Effect display
After struggling for a long time, I finally extracted the menu style and Tab page effects from the project.
1. The effect of initial loading
2. Expand menu (supports multi-level expansion, code introduction below)
3. Click the submenu to open the corresponding page in the form of a Tab page
4. Support menu folding
5. When there are too many open menus, they will automatically wrap into new lines and display automatically after folding
2. Code examples
There are ready-made things that are very convenient to use. Generally speaking, the functions of the Bootstrap Ace template are relatively powerful and support various terminal devices. This article mainly uses the effect of its menu. Let’s take a look at the implementation code of the Ace template menu effect.
1. Menu effect
Since Ace is based on Bootstrap, you first need to reference the jquery and bootstrap components. Let's take a general look at which files it needs to reference.
<script src="/Scripts/jquery-1.9.1.min.js"></script> <script src="/Content/bootstrap/js/bootstrap.min.js"></script> <link href="/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" /> <link href="/Content/font-awesome/css/font-awesome.min.css" rel="stylesheet" /> <link href="/Content/ace/css/ace-rtl.min.css" rel="stylesheet" /> <link href="/Content/ace/css/ace-skins.min.css" rel="stylesheet" /> <link href="/Content/sidebar-menu/sidebar-menu.css" rel="stylesheet"/> <script src="/Content/ace/js/ace-extra.min.js"></script> <script src="/Content/ace/js/ace.min.js"></script> <script src="/Content/sidebar-menu/sidebar-menu.js"></script>
Haha, it looks like there are quite a lot. Except for the last js file () which is encapsulated by the blogger himself, the others are basically the feature components required by the components. . Take a look at which html tags should be placed on the page:
<div class="sidebar" id="sidebar"> <ul class="nav nav-list" id="menu"></ul> <div class="sidebar-collapse" id="sidebar-collapse"> <i class="icon-double-angle-left" data-icon1="icon-double-angle-left" data-icon2="icon-double-angle-right"></i> </div> </div>
Let’s take a look at the encapsulation method in the sidebar-menu.js file:
(function ($) { $.fn.sidebarMenu = function (options) { options = $.extend({}, $.fn.sidebarMenu.defaults, options || {}); var target = $(this); target.addClass('nav'); target.addClass('nav-list'); if (options.data) { init(target, options.data); } else { if (!options.url) return; $.getJSON(options.url, options.param, function (data) { init(target, data); }); } var url = window.location.pathname; //menu = target.find("[href='" + url + "']"); //menu.parent().addClass('active'); //menu.parent().parentsUntil('.nav-list', 'li').addClass('active').addClass('open'); function init(target, data) { $.each(data, function (i, item) { var li = $('<li></li>'); var a = $('<a></a>'); var icon = $('<i></i>'); //icon.addClass('glyphicon'); icon.addClass(item.icon); var text = $('<span></span>'); text.addClass('menu-text').text(item.text); a.append(icon); a.append(text); if (item.menus&&item.menus.length>0) { a.attr('href', '#'); a.addClass('dropdown-toggle'); var arrow = $('<b></b>'); arrow.addClass('arrow').addClass('icon-angle-down'); a.append(arrow); li.append(a); var menus = $('<ul></ul>'); menus.addClass('submenu'); init(menus, item.menus); li.append(menus); } else { var href = 'javascript:addTabs({id:\'' + item.id + '\',title: \'' + item.text + '\',close: true,url: \'' + item.url + '\'});'; a.attr('href', href); //if (item.istab) // a.attr('href', href); //else { // a.attr('href', item.url); // a.attr('title', item.text); // a.attr('target', '_blank') //} li.append(a); } target.append(li); }); } } $.fn.sidebarMenu.defaults = { url: null, param: null, data: null }; })(jQuery);
Call the sidebar-menu method directly on the page
$(function () { $('#menu').sidebarMenu({ data: [{ id: '1', text: '系统设置', icon: 'icon-cog', url: '', menus: [{ id: '11', text: '编码管理', icon: 'icon-glass', url: '/CodeType/Index' }] }, { id: '2', text: '基础数据', icon: 'icon-leaf', url: '', menus: [{ id: '21', text: '基础特征', icon: 'icon-glass', url: '/BasicData/BasicFeature/Index' }, { id: '22', text: '特征管理', icon: 'icon-glass', url: '/BasicData/Features/Index' }, { id: '23', text: '物料维护', icon: 'icon-glass', url: '/Model/Index' }, { id: '24', text: '站点管理', icon: 'icon-glass', url: '/Station/Index' }] }, { id: '3', text: '权限管理', icon: 'icon-user', url: '', menus: [{ id: '31', text: '用户管理', icon: 'icon-user', url: '/SystemSetting/User' }, { id: '32', text: '角色管理', icon: 'icon-apple', url: '/SystemSetting/Role' }, { id: '33', text: '菜单管理', icon: 'icon-list', url: '/SystemSetting/Menu' }, { id: '34', text: '部门管理', icon: 'icon-glass', url: '/SystemSetting/Department' }] }, { id: '4', text: '订单管理', icon: 'icon-envelope', url: '', menus: [{ id: '41', text: '订单查询', icon: 'icon-glass', url: '/Order/Query' }, { id: '42', text: '订单排产', icon: 'icon-glass', url: '/Order/PLANTPRODUCT' }, { id: '43', text: '订单撤排', icon: 'icon-glass', url: '/Order/cancelPRODUCT' }, { id: '44', text: '订单HOLD', icon: 'icon-glass', url: '/Order/hold' }, { id: '45', text: '订单删除', icon: 'icon-glass', url: '/Order/delete' }, { id: '47', text: '订单插单', icon: 'icon-glass', url: '/Order/insertorder' }, { id: '48', text: '订单导入', icon: 'icon-glass', url: '/Order/Import' }] }] }); });
A very important point to note here is about the small icon in front of the menu:
When the value of con is icon-user, a small icon as shown in the picture will be displayed on the menu. Of course, under normal circumstances, the menu must be loaded dynamically. If you need to get data from the background, you can call this method directly:
$('#menu').sidebarMenu({ url: "/api/UserApi/GetMenuByUser/", param: { strUser: 'admin' } });
That’s it, haha, it’s very simple.
2. Tab page effect
The effect of the Tab page is actually closely related to the left menu. First, let’s take a look at the js reference of the Tab page effect.
HTML tag of the page:
<div class="main-content"><div class="page-content"> <div class="row"> <div class="col-xs-12" style="padding-left:5px;"> <ul class="nav nav-tabs" role="tablist"> <li class="active"><a href="#Index" role="tab" data-toggle="tab">首页</a></li> </ul> <div class="tab-content"> <div role="tabpanel" class="tab-pane active" id="Index"> </div> </div> </div> </div> </div> </div>
var addTabs = function (options) { //var rand = Math.random().toString(); //var id = rand.substring(rand.indexOf('.') + 1); var url = window.location.protocol + '//' + window.location.host; options.url = url + options.url; id = "tab_" + options.id; $(".active").removeClass("active"); //如果TAB不存在,创建一个新的TAB if (!$("#" + id)[0]) { //固定TAB中IFRAME高度 mainHeight = $(document.body).height() - 90; //创建新TAB的title title = '<li role="presentation" id="tab_' + id + '"><a href="#' + id + '" aria-controls="' + id + '" role="tab" data-toggle="tab">' + options.title; //是否允许关闭 if (options.close) { title += ' <i class="glyphicon glyphicon-remove" tabclose="' + id + '"></i>'; } title += '</a></li>'; //是否指定TAB内容 if (options.content) { content = '<div role="tabpanel" class="tab-pane" id="' + id + '">' + options.content + '</div>'; } else {//没有内容,使用IFRAME打开链接 content = '<div role="tabpanel" class="tab-pane" id="' + id + '"><iframe src="' + options.url + '" width="100%" height="' + mainHeight + '" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="yes" allowtransparency="yes"></iframe></div>'; } //加入TABS $(".nav-tabs").append(title); $(".tab-content").append(content); } //激活TAB $("#tab_" + id).addClass('active'); $("#" + id).addClass("active"); }; var closeTab = function (id) { //如果关闭的是当前激活的TAB,激活他的前一个TAB if ($("li.active").attr('id') == "tab_" + id) { $("#tab_" + id).prev().addClass('active'); $("#" + id).prev().addClass('active'); } //关闭TAB $("#tab_" + id).remove(); $("#" + id).remove(); }; $(function () { mainHeight = $(document.body).height() - 45; $('.main-left,.main-right').height(mainHeight); $("[addtabs]").click(function () { addTabs({ id: $(this).attr("id"), title: $(this).attr('title'), close: true }); }); $(".nav-tabs").on("click", "[tabclose]", function (e) { id = $(this).attr("tabclose"); closeTab(id); }); });
So, when is the Addtabs method called? The answer is when registering the menu click event. This part of the code is available when the sidebar-menu component is encapsulated earlier. You can look at it above.
The above is a display of the menu and Tab page effects of the bootstrap ace template. In general, the basic functions are available, but the style of the menu needs to be adjusted. For example, after clicking a menu, the clicked menu needs to be selected. status. If your project also uses the bootstrap style, study the ace template and try it out.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Zend Studio 13.0.1
Powerful PHP integrated development environment