国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序實現左側滑欄過程解析

2024-07-22 01:17:39
字體:
來源:轉載
供稿:網友

前言

一直想給項目中的小程序設置側滑欄,將退出按鈕放到側滑中,但是小程序沒有提供相應的控件和API,因此只能自己手動實現,網上很多大神造的輪子很不錯,本文就在是站在巨人的肩膀上實現。

hexo圖片不顯示問題,可前往簡書

效果

先看看效果,我的側滑欄需要列出如下信息:

初始狀態下,左下角設置懸空按鈕

點擊懸空按鈕,側邊欄拉出,懸空按鈕旋轉180度

主頁內容向右滑動一定比例,并設置陰影遮罩

實現

首先將xml文件分為三部分,一部分是主頁內容,一部分是側滑欄內容,一部分是懸浮按鈕。

<!--index.wxml--><view><!-- 側邊滑動菜單 --> <view class="page-slidebar">  <view class="page-content">   <view class="userinfo">    <button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 點擊獲取頭像昵稱 </button>    <block wx:else>     <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>     <text class="userinfo-nickname">{{userInfo.nickName}}</text>    </block>   </view>   <view class="account-info">    <view class="account-info-item">用戶:{{YHMC}}</view>    <view class="account-info-item">賬號:{{YHZH}}</view>    <view class="account-info-item">角色:{{YHJS}}</view>    <view class="account-info-item">版本:{{version}}</view>   </view>   <view>    <view class='quit-view'>     <button class='quit-btn' bindtap='quit'>退出登錄</button>    </view>   </view>  </view> </view><!-- 主頁內容 --> <view bindtouchmove="tap_drag" bindtouchend="tap_end" bindtouchstart="tap_start" class="page-top {{open ? ['c-state','cover'] : ''}} ">  <view class="usermotto">   <text class="user-motto">{{motto}}</text>  </view> </view> <!-- 添加側拉懸浮按鈕 --> <view bindtap="openSlider">  <image class="floatbutton {{open ? 'c-button-open' : '' }}" src="../../img/floatbutton.png"></image> </view></view>

wxss文件,樣式文件中,主要是.c-state,.c-button-open,.cover三個樣式。

/**index.wxss**/.userinfo { display: flex; flex-direction: column; align-items: center;}.userinfo-avatar { width: 128rpx; height: 128rpx; margin: 20rpx; border-radius: 50%;}.userinfo-nickname { color: #aaa;}.account-info {  margin-top: 50rpx;}.account-info-item { display: flex; align-items: center; height: 54px; margin-left: 10rpx; border-bottom: 1px solid #eee;}/* 側邊欄樣式 */.page-slidebar {  height: 100%;  width: 65%;  position: fixed;  background-color:white;  z-index: 0;} /* 主頁樣式 */.page-top {  height: 100%;  position: fixed;  width: 100%;  background-color:white;  z-index: 0;  transition: All 0.4s ease;  -webkit-transition: All 0.4s ease;}/* 控制側邊欄的內容距離頂部的距離 */.page-content {  padding-top: 60rpx;}/* 當屏幕向左滑動,出現側邊欄的時候,主頁的動畫樣式 *//* scale:取值范圍 0~1 ,表示屏幕大小是原來的百分之幾,可以自己修改成 0.8 試下*//* translate(60%,0%) 表示向左滑動的時候,側邊欄占用平時的寬度為 60%  */.c-state {  transform: rotate(0deg) scale(1) translate(65%, 0%);  -webkit-transform: rotate(0deg) scale(1) translate(65%, 0%);}.floatbutton { position: fixed; width: 100rpx; height: 100rpx; bottom: 140rpx; left: 40rpx; z-index: 9999;}.c-button-open { transform: rotate(180deg) scale(1) translate(65%, 0%); -webkit-transform: rotate(180deg) scale(1) translate(65%, 0%); transition-duration:0.5s; -webkit-transition-duration: 0.5s; left: 60%;}/* 遮蓋層樣式 */.cover{  width: 100%;  height: 100%;  background-color:gray;  opacity: 0.5;  z-index: 9000;}.quit-view { height: 5%; width: 65%;}.quit-btn { position: fixed; bottom: 5rpx; z-index: 999; color: #fff; width: 65%; border-radius: 5rpx; background-color: #064acb;}            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 马边| 铅山县| 错那县| 颍上县| 武强县| 蓬莱市| 墨江| 黑龙江省| 赤水市| 和龙市| 从化市| 泗水县| 吉林省| 公安县| 柳林县| 界首市| 恭城| 攀枝花市| 太湖县| 达日县| 鱼台县| 含山县| 阿拉善右旗| 嘉荫县| 南靖县| 繁峙县| 沭阳县| 贡觉县| 临沭县| 玉山县| 信丰县| 同江市| 白银市| 乡城县| 城口县| 淮滨县| 尤溪县| 新和县| 齐河县| 久治县| 离岛区|