


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.

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
