angular實(shí)現(xiàn)導(dǎo)航菜單切換
本文實(shí)例為大家分享了angular實(shí)現(xiàn)導(dǎo)航菜單切換的具體代碼,供大家參考,具體內(nèi)容如下
js部分:
$scope.navArr=[{ ? ? ? ? task:{ ? ? ? ? ? ? title: "我的任務(wù)", ? ? ? ? ? ? showAdd: true, ? ? ? ? ? ? data:[ ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? title:'我的設(shè)計(jì)院', ? ? ? ? ? ? ? ? ? ? id:1, ? ? ? ? ? ? ? ? ? ? hasChild:false, ? ? ? ? ? ? ? ? ? ? active:true, ? ? ? ? ? ? ? ? }, ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? title:'我加入的設(shè)計(jì)院', ? ? ? ? ? ? ? ? ? ? id:2, ? ? ? ? ? ? ? ? ? ? hasChild:true, ? ? ? ? ? ? ? ? ? ? active:false, ? ? ? ? ? ? ? ? ? ? data:[ ? ? ? ? ? ? ? ? ? ? ? ? {title:"設(shè)計(jì)院1",active:true}, ? ? ? ? ? ? ? ? ? ? ? ? {title:"設(shè)計(jì)院2",active:false} ? ? ? ? ? ? ? ? ? ? ] ? ? ? ? ? ? ? ? }, ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? title:'驗(yàn)證消息', ? ? ? ? ? ? ? ? ? ? id:3, ? ? ? ? ? ? ? ? ? ? hasChild:false, ? ? ? ? ? ? ? ? ? ? active:false, ? ? ? ? ? ? ? ? }, ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? title:'我參與的設(shè)計(jì)院', ? ? ? ? ? ? ? ? ? ? id:3, ? ? ? ? ? ? ? ? ? ? hasChild:true, ? ? ? ? ? ? ? ? ? ? active:false, ? ? ? ? ? ? ? ? ? ? data:[ ? ? ? ? ? ? ? ? ? ? ? ? {title:"設(shè)計(jì)院3",active:true}, ? ? ? ? ? ? ? ? ? ? ? ? {title:"設(shè)計(jì)院4",active:false} ? ? ? ? ? ? ? ? ? ? ] ? ? ? ? ? ? ? ? }, ? ? ? ? ? ? ] ? ? ? ? } ? ? ? ? }]; ? ?? ? ? $scope.showItem=false; ? ? $scope.showId=null; ? ? //給菜單項(xiàng)添加事件 ? ? $scope.changNavMenu=function(item,arr,hasChild){ ? ? ? ? for(let i of arr){ ? ? ? ? ? ? if(i==item){ ? ? ? ? ? ? ? ? i.active=true; ? ? ? ? ? ? ? ? showNav(hasChild,i.id) ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? i.active=false;? ? ? ? ? ? ? } ? ? ? ? } ? ? } ? ? function showNav(hasChild,id){ ? ? ? ? if($scope.showId!=id){ ? ? ? ? ? ? $scope.showItem=false; ? ? ? ? ? ? $scope.showId=id; ? ? ? ? } ? ? ? ? if(hasChild){ ? ? ? ? ? ? if($scope.showItem==false){ ? ? ? ? ? ? ? ? $scope.showItem=true ? ? ? ? ? ? }else if($scope.showItem==true){ ? ? ? ? ? ? ? ? $scope.showItem=false ? ? ? ? ? ? } ? ? ? ? } ? ? } ? ? // 給二級(jí)菜單添加點(diǎn)擊事件 ? ? $scope.changTwoNav=function(item,arr){ ? ? ? ? for(let i of arr){ ? ? ? ? ? ? if(i==item){ ? ? ? ? ? ? ? ? i.active=true; ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? i.active=false;? ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? event.stopPropagation(); ? ? }
html片段:
<div class="two_level_box"> ? <!-- title --> ? <p class="menu-title">{{navArr[0].task.title}}</p> ? <!-- add --> ? <div class="add-pro-btn" ng-if="navArr[0].task.showAdd"> ? ? <span>+ 快速立項(xiàng)</span> ? </div> ? <!--一級(jí)菜單--> ? <ul class="navMenu"> ? ? <li ng-click="changNavMenu(item,navArr[0].task.data,item.hasChild)" ng-class="{active:item.active}" ng-repeat="item in navArr[0].task.data"> ? ? ? <a href=""><b ng-class="{b_active:showItem&&item.active}" ng-if="item.hasChild"></b> {{item.title}}</a> ? ? ? <ul class="subMenu closeSubMenu" ng-class="{true:'subMenu',false:'closeSubMenu'}[showItem&&item.active]"> ? ? ? ? <li ng-if="item.hasChild" ng-class="{active:i.active&&item.active}" ng-click="changTwoNav(i,item.data)" ng-repeat="i in item.data"> ? ? ? ? ? ? <a href="">{{i.title}}</a> ? ? ? ? </li> ? ? ? </ul> ? ? </li> ? </ul> ? </ul> </div>
css:
.two_level_box{ ? float:left; ? width: 139px; ? height: 100%; ? background: #fff; } .menu-title{ ? margin:10px; } .add-pro-btn{ ? cursor: pointer; ? margin:10px; } .add-pro-btn span{ ? display: inline-block; ? width:100%; ? text-align: center; ? border:1.5px solid #EE6133; ? border-radius: 20px; ? padding:2px; ? color:#EE6133; } .navMenu>li>a{ ? margin:8px 0; ? padding:10px; } .navMenu>li{ ? margin:8px 0; ? padding:0; } .navMenu li a{ ? color:#000; } .navMenu>.active>a{ ? color:#EE6133; } .subMenu .active{ ? background-color: #FACFC1; ? border-right:2px solid #EE6133; } .closeSubMenu{ ? display: none; } .subMenu li{ ? padding:5px 0; ? border-right:2px solid #fff; } .subMenu li a{ ? padding-left:30px; } .navMenu b{ ? display: inline-block; ? width:8px; ? height:0; ? border-left:5px solid #A9A9A9; ? border-top:4px solid transparent; ? border-bottom:4px solid transparent; } .navMenu .b_active{ ? border-top:5px solid #A9A9A9; ? border-left:4px solid transparent; ? border-right:4px solid transparent; }
實(shí)現(xiàn)效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
AngularJS路由切換實(shí)現(xiàn)方法分析
這篇文章主要介紹了AngularJS路由切換實(shí)現(xiàn)方法,結(jié)合具體實(shí)例形式分析了AngularJS路由切換的實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-03-03教你用AngularJS框架一行JS代碼實(shí)現(xiàn)控件驗(yàn)證效果
簡(jiǎn)單來(lái)說(shuō)Angular.js是google開(kāi)發(fā)者設(shè)計(jì)和開(kāi)發(fā)的一套前端開(kāi)發(fā)框架,幫助你簡(jiǎn)化前端開(kāi)發(fā)的負(fù)擔(dān)。到底能簡(jiǎn)化到什么程度呢,今天我們來(lái)看下,一行代碼實(shí)現(xiàn)控件驗(yàn)證效果,有木有嚇尿?2014-06-06Angularjs注入攔截器實(shí)現(xiàn)Loading效果
angularjs作為一個(gè)全ajax的框架,對(duì)于請(qǐng)求,如果頁(yè)面上不做任何操作的話,在結(jié)果反回來(lái)之前,頁(yè)面是沒(méi)有任何響應(yīng)的,不像普通的HTTP請(qǐng)求,會(huì)有進(jìn)度條之類2015-12-12詳解AngularJS中module模塊的導(dǎo)入導(dǎo)出
本文給大家介紹angularjs中module模塊的導(dǎo)入導(dǎo)出,涉及到angularjs module相關(guān)知識(shí),對(duì)angularjs module感興趣的朋友一起看看吧2015-12-12AngularJS實(shí)現(xiàn)動(dòng)態(tài)添加Option的方法
這篇文章主要介紹了AngularJS實(shí)現(xiàn)動(dòng)態(tài)添加Option的方法,涉及AngularJS事件響應(yīng)及頁(yè)面元素動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-05-05Angular實(shí)現(xiàn)的日程表功能【可添加及隱藏顯示內(nèi)容】
這篇文章主要介紹了Angular實(shí)現(xiàn)的日程表功能,帶有向日程表中添加內(nèi)容及隱藏顯示內(nèi)容的功能,涉及AngularJS事件響應(yīng)及頁(yè)面元素動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-12-12Angular中使用Api 代理的實(shí)現(xiàn)
我們對(duì)接的過(guò)程中總是遇到跨域的問(wèn)題,本文使用 angualr 來(lái)講解代理api對(duì)接的話題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04