uniapp开发小程序-实现中间凸起的 tabbar

一、效果展示:

在这里插入图片描述

二、代码实现:

1.首先在pages.json文件中进行tabbar的样式和列表配置,代码如下:
{
   
   
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
   
   
			"path": "pages/index/index"
uniApp开发小程序中,如果你想自定义 tabBar 的样式并使其中间按钮凸起,并且点击该按钮时弹出一个弹框,你可以按照以下步骤操作: 1. 首先,在项目中引入需要的样式文件,通常在 `pages/index/index.wxss` 或者全局 CSS 文件中定义样式。 ```css .tab-bar-custom { display: flex; justify-content: space-between; align-items: center; } .tab-bar-item-center { position: relative; background-color: #fff; /* 设置中间按钮的基础颜色 */ border-radius: 50%; /* 给按钮圆角 */ overflow: hidden; } .tab-bar-item-center::before { content: ""; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 80%; height: 40%; background-color: rgba(0, 0, 0, 0.1); /* 边框阴影颜色 */ border-radius: 50%; box-shadow: inset 0px 5px 10px rgba(0, 0, 0, 0.2); /* 内阴影效果 */ transition: all 0.2s ease-in-out; /* 动画过渡 */ } .tab-bar-item-center:hover::before, .tab-bar-item-center.active::before { width: 100%; height: 100%; } ``` 2. 然后,在对应的页面组件 `.wxml` 文件中,设置 tabBar 的结构,并给中间按钮添加 click 事件监听: ```html <view class="tab-bar custom-tab-bar"> <view class="tab-bar-item tab-bar-item-left">左按钮</view> <view class="tab-bar-item tab-bar-item-center active" @click="showPopup">中间按钮</view> <view class="tab-bar-item tab-bar-item-right">右按钮</view> </view> <!-- 弹窗组件 --> <view id="popup" class="popup" v-if="isPopupVisible" @close="hidePopup"> <text>弹框内容</text> </view> ``` 3. 在 JavaScript 部分编写点击事件处理函数以及状态控制: ```javascript Page({ data: { isPopupVisible: false, // 初始化弹框可见状态 }, showPopup: function() { this.setData({ isPopupVisible: true }); // 显示弹框 }, hidePopup: function() { this.setData({ isPopupVisible: false }); // 隐藏弹框 }, }) ``` 当用户点击中间的按钮时,会触发 `showPopup` 函数,弹窗组件将会显示,而当用户关闭弹框时,会调用 `hidePopup` 函数。记得在你需要的地方导入 CSS 和 JS 文件,并在项目的 `app.json` 中配置 tabBar
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值