微信小程序?qū)崿F(xiàn)自定義底部導(dǎo)航
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)底部導(dǎo)航的具體代碼,供大家參考,具體內(nèi)容如下
建一個(gè)tabbar.wxml組件
<template name="tabBar"> <view class="tab-bar" style="color: {{tabBar.color}}; background: {{tabBar.backgroundColor}}; {{tabBar.position=='top'? 'top: 0' : 'bottom: 0'}};"> <block wx:for="{{tabBar.list}}" wx:key="pagePath"> <navigator hover-class="none" url="{{item.pagePath}}" open-type="redirect" class="tabbar_item {{item.clas}}" style="{{item.active? 'color: '+(item.selectedColor? item.selectedColor : tabBar.selectedColor) : ''}};position:relative;"> <image src="{{item.selectedIconPath}}" wx:if="{{item.active&&item.selectedIconPath}}" class="img"></image> <image src="{{item.iconPath}}" wx:if="{{!item.active&&item.iconPath}}" class="img"></image> <image src="{{item.logo}}" wx:if="{{item.logo}}" style="width:110rpx;height:110rpx;border:10rpx solid #ffffff;border-radius:50%;position:absolute;top:-50%;left:-40%,"></image> <text class="tabbar_text" wx:if="{{item.text}}">{{item.text}}</text> </navigator> </block> </view> </template>
app.js中定義
editTabBar: function () { //使用getCurrentPages可以獲取當(dāng)前加載中所有的頁面對(duì)象的一個(gè)數(shù)組,數(shù)組最后一個(gè)就是當(dāng)前頁面。 var curPageArr = getCurrentPages(); //獲取加載的頁面 var curPage = curPageArr[curPageArr.length - 1]; //獲取當(dāng)前頁面的對(duì)象 var pagePath = curPage.route; //當(dāng)前頁面url if (pagePath.indexOf('/') != 0) { pagePath = '/' + pagePath; } var tabBar = this.globalData.tabBar; for (var i = 0; i < tabBar.list.length; i++) { tabBar.list[i].active = false; if (tabBar.list[i].pagePath == pagePath) { tabBar.list[i].active = true; //根據(jù)頁面地址設(shè)置當(dāng)前頁面狀態(tài) } } curPage.setData({ tabBar: tabBar }); }, globalData: { tabBar: { "color": "#B0B6B8", "selectedColor": "#4877BD", "backgroundColor": "#ffffff", "borderStyle": "#ccc", "list": [{ "pagePath": "/pages/messagelist/messagelist", "text": "消息", "iconPath": "/img/message-1.png", "selectedIconPath": "/img/message-2.png", "selectedColor": "#4877BD", "clas": "menu-item", active: false }, { "pagePath": "/pages/salefriend/salefriend", "text": "名片", "iconPath": "/img/card-1.png", "selectedIconPath": "/img/card-2.png", "selectedColor": "#4877BD", "clas": "menu-item", active: false }, { "pagePath": "/pages/customnav/customnav", "text": "", // "iconPath": "/img/gifts.png", // "selectedIconPath": "/img/gifts.png", "logo":"/img/logo.png", "selectedColor": "#4877BD", "clas": "menu-item", islogo:true, active: false }, { "pagePath": "/pages/salescircle/salescircle", "text": "發(fā)現(xiàn)", "iconPath": "/img/discover-1.png", "selectedIconPath": "/img/discover-2.png", "selectedColor": "#4877BD", "clas": "menu-item", active: false }, { "pagePath": "/pages/mine/mine", "text": "我的", "iconPath": "/img/mine-1.png", "selectedIconPath": "/img/mine-2.png", "selectedColor": "#4877BD", "clas": "menu-item", active: false } ], "position": "bottom" }, },
在需要用的導(dǎo)航的頁面的wxml
<import src="/components/tabbar.wxml" /> <template is="tabBar" data="{{tabBar}}" />
在需要用的導(dǎo)航的頁面的js中
const app = getApp(); onShow: function () { app.editTabBar(); //顯示自定義的底部導(dǎo)航 },
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
uniapp使用navigateBack方法返回上級(jí)頁面并刷新的簡(jiǎn)單示例
最近寫uniapp項(xiàng)目的時(shí)候發(fā)現(xiàn)有時(shí)候需要更新頁面數(shù)據(jù),所以下面這篇文章主要給大家介紹了關(guān)于uniapp使用navigateBack方法返回上級(jí)頁面并刷新的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03用javascript對(duì)一個(gè)json數(shù)組深度賦值示例
本節(jié)主要介紹了用javascript對(duì)一個(gè)json數(shù)組深度賦值的具體實(shí)現(xiàn),需要的朋友可以參考下2014-07-07JavaScript Event學(xué)習(xí)第四章 傳統(tǒng)的事件注冊(cè)模型
在這一章我會(huì)講解給元素注冊(cè)事件的最好的一種辦法,那就是:確保一個(gè)特定的事件在特定的HTML元素上發(fā)生并且能運(yùn)行特定的腳本。2010-02-02JS庫之Particles.js中文開發(fā)手冊(cè)及參數(shù)詳解
因?yàn)樽约盒枰霎a(chǎn)品,所以一個(gè)好的UI界面也是很重要的,發(fā)現(xiàn)這種散射的原子顆粒特效還不錯(cuò)。今天腳本之家小編把Particles.js中文開發(fā)手冊(cè)及particles.js參數(shù)分享給大家,需要的朋友參考下吧2017-09-09淺談javascript函數(shù)劫持[轉(zhuǎn)自xfocus]
javascript函數(shù)劫持,也就是老外提到的javascript hijacking技術(shù)。最早還是和劍心同學(xué)討論問題時(shí)偶然看到的一段代碼2008-02-02使用JS前端技術(shù)實(shí)現(xiàn)靜態(tài)圖片局部流動(dòng)效果
本文使用前端開發(fā)技術(shù),結(jié)合?SVG?和?CSS?來實(shí)現(xiàn)類似的液化流動(dòng)效果,包含的知識(shí)點(diǎn)主要包括:mask-image?遮罩、feTurbulence?和?feDisplacementMap?濾鏡、filter?屬性、canvas?繪制方法、TimelineMax?動(dòng)畫及input[type=file]?本地圖片資源加載,需要的朋友可以參考下2022-08-08js實(shí)現(xiàn)登錄注冊(cè)框手機(jī)號(hào)和驗(yàn)證碼校驗(yàn)(前端部分)
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)登錄注冊(cè)框手機(jī)號(hào)和驗(yàn)證碼校驗(yàn)的前端部分代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09