微信小程序MUI導(dǎo)航欄透明漸變功能示例(通過改變r(jià)gba的a值實(shí)現(xiàn))
本文實(shí)例講述了微信小程序MUI導(dǎo)航欄透明漸變功能。分享給大家供大家參考,具體如下:
導(dǎo)航欄透明漸變效果
實(shí)現(xiàn)原理
1. 給page-group設(shè)置的背景顏色采用rgba;
2. 通過改變rgba其中a的值來實(shí)現(xiàn)透明漸變。
WXML
<view style="height:100%;position:fixed;width:100%;"> <scroll-view scroll-y="false" bindscroll="scroll" style="height:100%;"> <!-- 改變位置,去掉多余的view,直接改變背景色的透明度實(shí)現(xiàn)透明漸變 --> <view class="page-group" style="background-color: rgba(138, 43, 226,{{scrollTop / 400 > 0.9 ? 0.9 : scrollTop / 400}});"> <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;} /*去掉多余的class,直接設(shè)置背景色為rgba格式*/ .page-group{ display: table; width: 100%; table-layout: fixed; background-color: rgba(138, 43, 226,0); position: fixed; top: 0; left: 0; z-index: 10; } .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 }, //滾動條監(jiān)聽 scroll: function (e) { this.setData({ scrollTop: e.detail.scrollTop }) }, })
總結(jié):
1.優(yōu)點(diǎn)是去掉了多余的view空和class代碼,減少了代碼,實(shí)現(xiàn)了相同的效果。
2.缺點(diǎn)就是在微信開發(fā)者工具中,保存刷新不能獲取當(dāng)前位置scrollTop,只有滾動才能獲取scrollTop。
希望本文所述對大家微信小程序開發(fā)有所幫助。
相關(guān)文章
javascript利用初始化數(shù)據(jù)裝配模版的實(shí)現(xiàn)代碼
實(shí)現(xiàn)一個(gè)通用方法,使用初始化數(shù)據(jù)來裝配模版。需要的朋友可以參考下。2010-11-11關(guān)于ECharts設(shè)置x軸刻度間隔的兩種方式
這篇文章主要介紹了關(guān)于ECharts設(shè)置x軸刻度間隔的兩種方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02基于slideout.js實(shí)現(xiàn)移動端側(cè)邊欄滑動特效
這篇文章主要為大家詳細(xì)介紹了基于slideout.js實(shí)現(xiàn)移動端側(cè)邊欄滑動特效,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11vue3+Pinia+TypeScript?實(shí)現(xiàn)封裝輪播圖組件
這篇文章主要介紹了vue3+Pinia+TypeScript?實(shí)現(xiàn)封裝輪播圖組件,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-07-07僅img元素創(chuàng)建后不添加到文檔中會執(zhí)行onload事件的解決方法
僅img元素創(chuàng)建后不添加到文檔中會執(zhí)行onload事件的解決方法,需要的朋友可以參考下。2011-07-07uni-app開發(fā)微信小程序之H5壓縮上傳圖片的問題詳解
這次項(xiàng)目中做了一個(gè)圖片上傳,要求是大于2MB的就壓縮成2MB一下的再上傳,下面這篇文章主要給大家介紹了關(guān)于uni-app開發(fā)微信小程序之H5壓縮上傳圖片的問題,需要的朋友可以參考下2023-03-03JS實(shí)現(xiàn)的4種數(shù)字千位符格式化方法分享
這篇文章主要介紹了JS實(shí)現(xiàn)的4種數(shù)字千位符格式化方法分享,本文給出了4種千分位格式化方法并對它們的性能做了比較,需要的朋友可以參考下2015-03-03