微信小程序MUI导航栏透明渐变功能示例(通过改变opacity实现)
作者:Rattenking 时间:2024-05-11 09:42:26
本文实例讲述了微信小程序MUI导航栏透明渐变功能。分享给大家供大家参考,具体如下:
导航栏透明渐变效果
实现原理
1. 利用position:absolute
在导航下定位一个view作为背景渐变使用;
2. 通过改变改view的opacity来实现透明渐变。
WXML
<!--pages/scroll/scroll.wxml-->
<view style="height:100%;position:fixed;width:100%;">
<scroll-view scroll-y="false" bindscroll="scroll" style="height:100%;">
<view class="page-group">
<view class="page-group-position" style="opacity:{{scrollTop / 400 > 0.9 ? 0.9 : scrollTop / 400}}"></view>
<view class="page-nav-list"><text>首页</text></view>
<view class="page-nav-list"><text>活动</text></view>
<view class="page-nav-list"><text>菜单</text></view>
<view class="page-nav-list"><text>我的</text></view>
</view>
<view class="page-banner">
banner
</view>
<view class="goods-list">
goods-list1
</view>
<view class="goods-list list2">
goods-list2
</view>
<view class="goods-list list3">
goods-list3
</view>
<view class="goods-list list4">
goods-list4
</view>
</scroll-view>
</view>
WXSS
.page-banner{height: 500rpx;background-color: greenyellow;padding: 20rpx;color:#fff;padding-top: 100rpx;}
.page-group{
display: table;
width: 100%;
table-layout: fixed;
position: fixed;
top: 0;
left: 0;
z-index: 10;
}
.page-group-position{
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background-color: blueviolet;
opacity: 0;
z-index: -1;
}
.page-nav-list{
padding:30rpx 0 ;
display: table-cell;
text-align: center;
width: 100%;
color: #fff;
}
.goods-list{
height: 500rpx;
background-color: green;
padding: 20rpx;
color:#fff;
}
.list2{background-color: blue;}
.list3{background-color: yellow;}
.list4{background-color: red;}
JS
Page({
data: {
scrollTop: null
},
//滚动条监听
scroll: function (e) {
this.setData({ scrollTop: e.detail.scrollTop })
},
})
总结:
1. 需要scroll-view组件配合使用才能获取scrollTop;
2. scrollTop / 400 > 0.9,这里400的距离是根据需求改变,0.9是背景最后的半透明值,可以根据页面调节。
Demo源码:
点击此处本站下载。
希望本文所述对大家微信小程序开发有所帮助。
来源:https://blog.csdn.net/m0_38082783/article/details/78854045
标签:微信小程序,MUI,导航栏
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中的flask框架详解
2021-03-20 20:23:59
python Dataframe 合并与去重详情
2022-08-17 02:18:54
Python装饰器的应用场景及实例用法
2022-06-24 16:09:03
详解将DataGrip连接到MS SQL Server的方法
2024-01-17 00:41:14
![](https://img.aspxhome.com/file/2023/1/86891_0s.jpg)
python定时任务schedule库用法详细讲解
2022-11-01 10:19:29
![](https://img.aspxhome.com/file/2023/8/97768_0s.png)
通过Python绘制中国结的示例代码
2021-05-29 15:15:21
![](https://img.aspxhome.com/file/2023/4/102784_0s.png)
利用SQL Server触发器实现表的历史修改痕迹记录
2024-01-19 18:06:42
![](https://img.aspxhome.com/file/2023/7/99947_0s.jpg)
5个css布局的常见问题及解决方法
2009-11-19 13:21:00
![](https://img.aspxhome.com/file/UploadPic/200911/19/css_layout-83s.png)
Python Flask 转换器的使用详解
2023-06-30 15:42:09
![](https://img.aspxhome.com/file/2023/8/95228_0s.jpg)
使用Python AIML搭建聊天机器人的方法示例
2022-01-04 10:14:28
MySQL into_Mysql中replace与replace into用法案例详解
2024-01-26 20:10:00
python读取Excel表格文件的方法
2023-07-24 01:17:14
![](https://img.aspxhome.com/file/2023/2/75332_0s.jpg)
Python 取numpy数组的某几行某几列方法
2023-11-24 05:46:47
![](https://img.aspxhome.com/file/2023/5/64655_0s.png)
PHP适配器模式Adapter Pattern的使用介绍
2023-06-10 12:28:21
mysql 5.7版本修改密码的简单方法
2024-01-28 06:14:38
![](https://img.aspxhome.com/file/2023/1/77221_0s.png)
Golang sync包中errgroup的使用详解
2024-02-08 23:19:08
echarts柱状图坐标轴内容显示不全的两种解决办法
2023-09-06 03:57:34
![](https://img.aspxhome.com/file/2023/2/56122_0s.png)
在Pycharm中对代码进行注释和缩进的方法详解
2023-09-27 23:55:26
如何利用python正确地为图像添加高斯噪声
2023-08-03 08:26:22
![](https://img.aspxhome.com/file/2023/9/59459_0s.png)
kali中python版本的切换方法
2022-03-03 17:53:45
![](https://img.aspxhome.com/file/2023/7/93887_0s.jpg)