当前位置: 首页 > news >正文

uniapp实现中间平滑凸起tabbar

uniapp实现中间平滑凸起tabbar

  • 背景
  • 实现思路
  • 代码实现
  • 尾巴

背景

在移动端开发中,tabar是一个使用频率很高的组件,几乎是每个APP都会用到。今天给大家分享一个中间平滑凸起的tabbar组件,有需要的可以做下参考。先上图镇楼:
在这里插入图片描述

实现思路

看上面图片就知道这个难点只有一个,就是中间那个平滑的凸起tab怎么来实现。好了,我也不卖关子了,直接说下实现的思路:
1、先布局一个普通的tabbar
2、再利用clip-path来裁剪出一个平滑凸起的圆弧,通过设置position来盖在步骤1的普通tabbar上面。

代码实现

我们先布局出一个普通的tabbar并放置在屏幕底部。

/*省略部分代码*/
<view class="tabbar"><block v-for="(item, index) in tabbarList" :key="index"><view class="tabbar-item" @click="toIndex(index)"><image :src="current == index ? item.activeIcon : item.inactiveIcon"></image><text :class="'font-title' + (current == index ? '-active' : '')">{{item.title}}</text></view></block></view>
/*省略部分代码*/

tabbarList就是你存放的tabbar配置项为奇数个,格式如下:

/*省略部分代码*/
tabbarList: [{inactiveIcon: '../../static/tabbar/main_tab_home_normal.png',activeIcon: '../../static/tabbar/main_tab_home_select.png',title: '首页'}]
/*省略部分代码*/

这是效果如下:
在这里插入图片描述
接下来我们利用clip-path来裁剪出一个弧形的path,然后在tabbar中间盖一个你需要的图片,我这里是加号图。为了看的更直观,我将这个裁剪的弧形先不盖在tabbar上面,先偏移底部较大一段距离,看效果:
在这里插入图片描述
然后调整下偏移量到一个合适位置,就看到了文章中开始那个效果了。这个path的裁剪形状你可以直接参考我的。

/*省略部分代码*/
.mid-btn-arc {position: fixed;bottom: 250rpx;left: calc(50% - 100rpx);background-color: #fff;z-index: 98;height: 100rpx;width: 200rpx;clip-path: path('M 50,0 Q 35,0 25,7.5 Q 20.5, 11.5 0, 15 V 50 H 100 V15 Q 79.5,11.5 75,7.5 Q 65,0 50,0 z');}
/*省略部分代码*/

到这里基本就完工了。接下来贴出来全部的代码:

<template><view><view>{{content}}</view><view class="tabbar"><block v-for="(item, index) in tabbarList" :key="index"><view class="tabbar-item" @click="toIndex(index)"><image :src="current == index ? item.activeIcon : item.inactiveIcon"></image><text :class="'font-title' + (current == index ? '-active' : '')">{{item.title}}</text></view></block><view class="mid-btn-arc"></view><view class="mid-btn" @click="toIndex(tabbarList.length % 2)"><image class="mid-img" src="../../static/tabbar/add.png"></image></view></view></view>
</template><script>export default {data() {return {current: 0,content: '首页',tabbarList: [{inactiveIcon: '../../static/tabbar/main_tab_home_normal.png',activeIcon: '../../static/tabbar/main_tab_home_select.png',title: '首页'},{inactiveIcon: '../../static/tabbar/main_tab_home_normal.png',activeIcon: '../../static/tabbar/main_tab_home_select.png',title: '首页1'},{inactiveIcon: '../../static/tabbar/main_tab_home_normal.png',activeIcon: '../../static/tabbar/main_tab_home_select.png',title: '首页2'},{inactiveIcon: '../../static/tabbar/main_tab_home_normal.png',activeIcon: '../../static/tabbar/main_tab_home_select.png',title: '首页3'},{inactiveIcon: '../../static/tabbar/main_tab_home_normal.png',activeIcon: '../../static/tabbar/main_tab_home_select.png',title: '首页4'}]}},methods: {toIndex(index){this.current = indexthis.content = this.tabbarList[index].title}}}
</script><style lang="scss">page {background-color: #dfdfdf;}.tabbar {position: fixed;left: 0;bottom: 0;height: 120rpx;width: 100vw;background-color: #f9f9f9;z-index: 99;display: flex;justify-content: space-between;align-items: center;}.tabbar-item {flex: 1;height: 120rpx;background-color: #fff;z-index: 100;display: flex;flex-direction: column;justify-content: center;align-items: center;transition: transform 0.3s;}.font-title {font-size: 22rpx;margin: 5rpx 0;color: #dfdfdf;z-index: 100;}.font-title-active {font-size: 22rpx;margin: 5rpx 0;color: #000000;z-index: 100;}.mid-btn-arc {position: fixed;bottom: 50rpx;left: calc(50% - 100rpx);background-color: #fff;z-index: 98;height: 100rpx;width: 200rpx;clip-path: path('M 50,0 Q 35,0 25,7.5 Q 20.5, 11.5 0, 15 V 50 H 100 V15 Q 79.5,11.5 75,7.5 Q 65,0 50,0 z');}.mid-btn {position: fixed;height: 100rpx;width: 100rpx;left: 50%;bottom: 45rpx;transform: translateX(-50rpx);background-color: #fff;border-radius: 50rpx;display: flex;justify-content: center;align-items: center;z-index: 100;.mid-img {width: 80rpx;height: 80rpx;}}image {width: 50rpx;height: 50rpx;transition: transform 0.3s, width 0.3s, height 0.3s;}
</style>

我知道你只想直接ctrl+c在这里插入图片描述

啊什么,你还想要图片?给你,通通给你:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

尾巴

毫无保留啥都给你们了,有啥问题可以给我留言,如果喜欢我的文章,欢迎给我点赞,评论,关注,谢谢大家!

http://www.lryc.cn/news/474899.html

相关文章:

  • 【视频】OpenCV:识别颜色、绘制轮廓
  • C++_STL_xx_番外01_关于STL的总结(常见容器的总结;关联式容器分类及特点;二叉树、二叉搜索树、AVL树(平衡二叉搜索树)、B树、红黑树)
  • xlrd.biffh.XLRDError: Excel xlsx file; not supported
  • ENNSP中ACL的实验配置
  • 数字后端零基础入门系列 | Innovus零基础LAB学习Day8
  • 【AI开源项目】FastGPT- 快速部署FastGPT以及使用知识库的两种方式!
  • 信息学科平台系统开发:Spring Boot实用指南
  • 笔记本电脑买i7还是i9?i7和i9处理器区别详细介绍
  • Netty原来就是这样啊(一)
  • 量子容错计算
  • QGraphics View坐标系
  • 繁星之下--
  • Transformer+KAN系列时间序列预测代码
  • vue项目安装组件失败解决方法
  • C++ [项目] 躺平发育
  • [产品管理-55]:产品设计不仅仅完成功能,即可用性设计,还需要完成可生产性、可装配性、可维护性、可回收性、可服务性设计
  • Mount Image Pro,在取证安全的环境中挂载和访问镜像文件内容
  • 玩转Docker | Docker基础入门与常用命令指南
  • 【MySQL】MySQL安装以及各种报错处理
  • 【传知代码】图像处理解决种子计数方法
  • WPF 特性------Binding
  • 深入解析 FastAPI 查询参数:配置、类型转换与灵活组合
  • 大学城水电管理系统开发:Spring Boot指南
  • Lua 从基础入门到精通(非常详细)
  • [MySQL#11] 索引底层(2) | B+树 | 索引的CURD | 全文索引
  • 一个指针可以被声明为 `volatile`
  • [0260].第25节:锁的不同角度分类
  • android数组控件Textview
  • openpnp - 手工修改配置文件(元件高度,size,吸嘴)
  • Java 集合一口气讲完!(中)d=====( ̄▽ ̄*)b