微信小程序自定义tabbar导航栏,中间凸出样式

这篇具有很好参考价值的文章主要介绍了微信小程序自定义tabbar导航栏,中间凸出样式。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

这种样式的底部导航栏

微信小程序自定义tabbar导航栏,中间凸出样式

使用微信小程序的自定义tabBar:微信小程序官方说明

uni.app=>在 page.json 中的 tabBar 项指定 custom 字段为true:

	"tabBar": {
	   "custom": true,
		"color": "rgb(51, 51, 51)",
		"selectedColor": "rgb(249, 48, 43)",
		"backgroundColor": "rgb(196, 196, 196)",
		"list": [{
			"pagePath": "pages/index/index",
			"text": "首页",
			"iconPath": "/static/tabBar/taber_pictrue/home.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/home.png"
		}, {
			"pagePath": "pages/course/index",
			"text": "课程",
			"iconPath": "/static/tabBar/taber_pictrue/course.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/course.png"

		}, {
			"pagePath": "pages/bm/index",
			"text": "报名",
			"iconPath": "/static/tabBar/taber_pictrue/bm.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/bm.png"
		}, {
			"pagePath": "pages/data/index",
			"text": "资料",
			"iconPath": "/static/tabBar/taber_pictrue/data.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/data.png"

		}, {
			"pagePath": "pages/myCenter/index",
			"text": "我的",
			"iconPath": "/static/tabBar/taber_pictrue/mycenter.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/mycenter.png"

		}]
	},

在根目录创建custom-tab-bar目录,注意一定要完全匹配,不要输错

custom-tab-bar/index.js
custom-tab-bar/index.json
custom-tab-bar/index.wxml
custom-tab-bar/index.wxss

微信小程序自定义tabbar导航栏,中间凸出样式

 index.js代码:注意这里的中间需要凸出项设置一个class

Component({
	data: {
		selected: 0, //当前选中的tab下标
		color: "#1E1E1E",
		selectedColor: "#646464", //tabbar选中字体颜色
		"list": [{
			"pagePath": "pages/index/index",
			"text": "首页",
			"iconPath": "/static/tabBar/taber_pictrue/home.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/home.png"
		}, {
			"pagePath": "pages/course/index",
			"text": "课程",
			"iconPath": "/static/tabBar/taber_pictrue/course.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/course.png"

		}, {
			"pagePath": "pages/bm/index",
			"text": "报名",
			"iconPath": "/static/tabBar/taber_pictrue/bm-2.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/bm.png",
			bmClass: "bm"
		}, {
			"pagePath": "pages/data/index",
			"text": "资料",
			"iconPath": "/static/tabBar/taber_pictrue/data.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/data.png"

		}, {
			"pagePath": "pages/myCenter/index",
			"text": "我的",
			"iconPath": "/static/tabBar/taber_pictrue/mycenter.png",
			"selectedIconPath": "/static/tabBar/taber_pictrue_selected/mycenter.png"
		}]
	},
	attached() {},
	methods: {
		toggleTabbar(e) {
			const data = e.currentTarget.dataset;
			const url ='/' + data.path
			// this.setData({
			// 	selected: data.index
			// })
			wx.switchTab({url})
		}
	},
})

index.json代码:

{
  "component": true,
  "usingComponents": {}
}

index.wxml代码:动态设置中间凸出项的class,css样式可根据自己项目要求进行更改:

<view>
	<view  class="tab-bar" >
		<image class="tab-bar-bg" src="../static/tabBar/taber_pictrue/tabbar.png"></image>
		<view class="tab-bar-icon tab-bar">
			<view wx:for="{{list}}" wx:key="index" class="tab-bar-item {{item.diyClass}}" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="toggleTabbar">
			  <image src="{{selected === index ? item.selectedIconPath : item.iconPath}}" class="{{item.bmClass}}"  mode="aspectFit"/>
			  <view style="color: {{selected === index ? selectedColor : color}}" class="{{item.bmClass}}">{{item.text}}</view>
			</view>
		</view>
	</view>

</view>

index.wxss代码:

/*重新样式*/
.tab-bar {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	display: flex;
	box-sizing: content-box;
	background-color: transparent;
}

.tab-bar-bg {
	width: 100%;
	height: 140rpx;

}

.tab-bar-icon {
	display: flex;
	position: absolute;
	justify-content: space-between;
	width: 100%;
}

.tab-bar-border {
	background-color: rgba(0, 0, 0, 0.33);
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 1px;
	transform: scaleY(0.5);
}

.tab-bar-item {
	flex: auto;
	text-align: center;
	display: flex;
	justify-content: center;
	align-items: center;
	flex-direction: column;
	background-color: transparent;
	height: 120rpx;
}

.tab-bar-item.bm {
	margin-top: 0 !important;
	background: transparent;
	position: relative;
	flex: inherit;
	width: 134rpx;
}

.tab-bar-item image {
	width: 48rpx;
	height: 48rpx;
	overflow: initial;
}

.tab-bar-item view {
	font-size: 24rpx;
}

.tab-bar-item image.bm {
	position: absolute;
	width: 108rpx;
	height: 106rpx;
	bottom: 80%;
	z-index: 100;
}

.tab-bar-item view.bm {
	background: transparent;
	width: 100%;
	height: 100%;
	padding-top: 73rpx;
	z-index: 99;
}

有用可以点赞收藏,嘿嘿~文章来源地址https://www.toymoban.com/news/detail-489150.html

到了这里,关于微信小程序自定义tabbar导航栏,中间凸出样式的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • uni-app 微信小程序之自定义中间圆形tabbar

    首先在 pages.json 文件中,新建一个 tabbar 页面 此页面主要是写 tabbar的html样式和布局,引用主页面代码,通过 v-if 控制进行展示 index , search , maim , news , me 一级页面 css 样式文件太多了就不贴出来了

    2024年02月03日
    浏览(40)
  • 微信小程序自定义导航栏机型适配--底部Tabbar--view高度--底部按钮适配

    自定义微信小程序头部导航栏 自定义微信小程序头部导航栏,有几种方式 方式一 定义此方法后,头部的导航栏会去掉,导航栏下的元素会直接向上移动到原导航栏的位置,可以再app.json配置成全局沉浸式导航栏,以及在单页面配置沉浸式导航栏。 方式二 使用组件 这里使用

    2024年02月02日
    浏览(42)
  • uniapp通过custom-tab-bar 自定义tabbar导航栏(主要用于微信小程序)

    这个自定义的tabbar是用于微信小程序方面的 开始: uniapp文档搜索自定义tabbar,并找到这个 第一步: 根目录创建 custom-tab-bar 文件,并在page.json文件里面tabbar设置项中添加 custom 属性,并设置为 true,list数组不要清空,把你得tabbar页面也写上去,他需要和你得自定义得tabbar那个数组对照

    2024年04月09日
    浏览(46)
  • 微信小程序—tabBar导航栏

    1、什么是tabBar? tabBar是移动端应用常见的页面效果,用于实现多页面的快速切换。小程序中常分为: 底部 tabBar 顶部 tabBar 2、tabBar 节点的配置项 position :tabBar的位置,仅支持bottom/top border :tabBar上边框的颜色,仅支持black/white color :tab上文字的默认颜色 selectedColor :tab上文

    2024年02月08日
    浏览(34)
  • uniapp使用vue3和ts开发小程序自定义tab栏,实现自定义凸出tabbar效果

    要实现自定义的tabbar效果,可以使用自定义tab覆盖主tab来实现,当程序启动或者从后台显示在前台时隐藏自带的tab来实现。自定义一个tab组件,然后在里面实现自定义的逻辑。 组件中所使用的组件api可以看:Tabbar 底部导航栏 | uView 2.0 - 全面兼容 nvue 的 uni-app 生态框架 - uni-

    2024年02月04日
    浏览(32)
  • 【微信小程序】在非tabbar页面使用导航栏进行切换

    当在我们做微信小程序项目时会遇到有多个端口的项目需求,然而多个端口意味着多个导航栏。但微信小程序仅支持使用 app.json 创建 一个导航栏 (如下图) 在app.json中配置的tabbar app.json 所以我们只能自己制作导航栏并且使用页面路由方式来进行页面跳转(如 wx.navigateTo; w

    2024年02月13日
    浏览(38)
  • 微信小程序使用tabbar时,导航框不显示

    当我们使用微信小程序时,使用了正确的格式去使用导航框,但是没有显示时。 首先查看一下是否把写了自定义了,如: 把“custom”删去或者改成false也可以。 跳转不成功的话,观察路径是否正确,因为有些是“pages/index/index”,也有可能是“index/index” 最好是在pages里面复

    2024年02月13日
    浏览(39)
  • 微信小程序底部导航跳转tabBar页不触发onLoad

    .js加上onTabItemTap();方法

    2024年02月09日
    浏览(36)
  • 微信小程序-获取设备信息,状态栏/导航栏/内容/tabBar高度设置

    效果展示  代码展示

    2024年02月11日
    浏览(48)
  • 优雅实现微信小程序动态tabBar,根据不同用户角色显示不同底部导航

    背景 在开发小程序过程中,有个需求是,小程序底部的tabBar需要根据不同用户角色显示不同底部导航。此时就需要用到自定义底部导航 custom-tab-bar。 上次发文是组合显示4个底部tabBar导航,很多小伙伴评论说组合超过5个怎么办。他们的需求总数超过5个了。 现在我在这里更新

    2024年02月14日
    浏览(26)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包