欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)崿F(xiàn)左側(cè)滑欄過(guò)程解析

 更新時(shí)間:2019年08月26日 09:56:45   作者:Numen.fan  
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)左側(cè)滑欄過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

前言

一直想給項(xiàng)目中的小程序設(shè)置側(cè)滑欄,將退出按鈕放到側(cè)滑中,但是小程序沒(méi)有提供相應(yīng)的控件和API,因此只能自己手動(dòng)實(shí)現(xiàn),網(wǎng)上很多大神造的輪子很不錯(cuò),本文就在是站在巨人的肩膀上實(shí)現(xiàn)。

hexo圖片不顯示問(wèn)題,可前往簡(jiǎn)書

效果

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

初始狀態(tài)下,左下角設(shè)置懸空按鈕

點(diǎn)擊懸空按鈕,側(cè)邊欄拉出,懸空按鈕旋轉(zhuǎn)180度

主頁(yè)內(nèi)容向右滑動(dòng)一定比例,并設(shè)置陰影遮罩

實(shí)現(xiàn)

首先將xml文件分為三部分,一部分是主頁(yè)內(nèi)容,一部分是側(cè)滑欄內(nèi)容,一部分是懸浮按鈕。

<!--index.wxml-->
<view>
<!-- 側(cè)邊滑動(dòng)菜單 -->
 <view class="page-slidebar">
  <view class="page-content">
   <view class="userinfo">
    <button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 點(diǎn)擊獲取頭像昵稱 </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">賬號(hào):{{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>
<!-- 主頁(yè)內(nèi)容 -->
 <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>
 <!-- 添加側(cè)拉懸浮按鈕 -->
 <view bindtap="openSlider">
  <image class="floatbutton {{open ? 'c-button-open' : '' }}" src="../../img/floatbutton.png"></image>
 </view>
</view>

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

/**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;
}


/* 側(cè)邊欄樣式 */
.page-slidebar {
  height: 100%;
  width: 65%;
  position: fixed;
  background-color:white;
  z-index: 0;
}
 /* 主頁(yè)樣式 */
.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;
}

/* 控制側(cè)邊欄的內(nèi)容距離頂部的距離 */
.page-content {
  padding-top: 60rpx;
}

/* 當(dāng)屏幕向左滑動(dòng),出現(xiàn)側(cè)邊欄的時(shí)候,主頁(yè)的動(dòng)畫樣式 */
/* scale:取值范圍 0~1 ,表示屏幕大小是原來(lái)的百分之幾,可以自己修改成 0.8 試下*/
/* translate(60%,0%) 表示向左滑動(dòng)的時(shí)候,側(cè)邊欄占用平時(shí)的寬度為 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;
}

js文件,這里不涉及我demo中申請(qǐng)用戶信息內(nèi)容。

// 點(diǎn)擊左下角小圖標(biāo)事件
 openSlider: function (e) {
  if (this.data.open) {
   this.setData({
    open: false
   });
  } else {
   this.setData({
    open: true
   });
  }
 },
 tap_start: function (e) {
  // touchstart事件
  // 把手指觸摸屏幕的那一個(gè)點(diǎn)的 x 軸坐標(biāo)賦值給 mark 和 newmark
  this.data.mark = this.data.newmark = e.touches[0].pageX;
 },
 tap_drag: function (e) {
  // touchmove事件
  this.data.newmark = e.touches[0].pageX;
  // 手指從左向右移動(dòng)
  if (this.data.mark < this.data.newmark) {
   this.istoright = true;
  }
  // 手指從右向左移動(dòng)
  if (this.data.mark > this.data.newmark) {
   this.istoright = false;
  }
  this.data.mark = this.data.newmark;
 },
 tap_end: function (e) {
  // touchend事件
  this.data.mark = 0;
  this.data.newmark = 0;
  // 通過(guò)改變 opne 的值,讓主頁(yè)加上滑動(dòng)的樣式
  if (this.istoright) {
   this.setData({
    open: true
   });
  } else {
   this.setData({
    open: false
   });
  }
 }

參考資料

微信小程序之側(cè)邊欄滑動(dòng)實(shí)現(xiàn)(附完整源碼)

微信小程序側(cè)邊欄滑動(dòng)特效(左右滑動(dòng))

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Svelte?和?React的比較詳解(一)

    Svelte?和?React的比較詳解(一)

    在這篇文章中,我將Svelte?還是?React作了對(duì)比,不能以個(gè)人意見(jiàn)代表誰(shuí)好誰(shuí)壞。以及我發(fā)現(xiàn)使用這兩個(gè)框架的一些區(qū)別,感興趣的小伙伴可以參考閱讀
    2023-04-04
  • javascript 閉包疑問(wèn)

    javascript 閉包疑問(wèn)

    今天在編碼時(shí),遇到一個(gè)問(wèn)題,特記錄下。希望對(duì)朋友有所幫助。
    2010-12-12
  • 淺談微信JS-SDK 微信分享接口開(kāi)發(fā)(介紹版)

    淺談微信JS-SDK 微信分享接口開(kāi)發(fā)(介紹版)

    這篇文章主要介紹了淺談微信JS-SDK 微信分享接口開(kāi)發(fā)(介紹版),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • JavaScript實(shí)現(xiàn)連連看連線算法

    JavaScript實(shí)現(xiàn)連連看連線算法

    這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)連連看連線算法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • js中substring和substr的詳細(xì)介紹與用法

    js中substring和substr的詳細(xì)介紹與用法

    這篇文章介紹了js中substring和substr的用法,有需要的朋友可以參考一下
    2013-08-08
  • 新浪中用來(lái)顯示flash的函數(shù)

    新浪中用來(lái)顯示flash的函數(shù)

    新浪中用來(lái)顯示flash的函數(shù)...
    2007-04-04
  • Javascript中實(shí)現(xiàn)String.startsWith和endsWith方法

    Javascript中實(shí)現(xiàn)String.startsWith和endsWith方法

    這篇文章主要介紹了Javascript中實(shí)現(xiàn)String.startsWith和endsWith方法,這兩個(gè)很好用的方法在JS中沒(méi)有,本文就自己編碼實(shí)現(xiàn)了這兩個(gè)方法,需要的朋友可以參考下
    2015-06-06
  • 微信小程序?qū)崿F(xiàn)上傳圖片小功能

    微信小程序?qū)崿F(xiàn)上傳圖片小功能

    這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)上傳圖片小功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • 深入理解es6塊級(jí)作用域的使用

    深入理解es6塊級(jí)作用域的使用

    這篇文章主要介紹了深入理解es6塊級(jí)作用域的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • JS面試之手寫節(jié)流防抖詳解

    JS面試之手寫節(jié)流防抖詳解

    作為一個(gè)程序員,代碼實(shí)現(xiàn)才是能力體現(xiàn),在大部分面試的時(shí)候,我們都會(huì)被要求手寫代碼實(shí)現(xiàn)一個(gè)功能,本文總結(jié)了一下經(jīng)常被面試官問(wèn)到的節(jié)流和防抖功能的實(shí)現(xiàn),分享給有需要的小伙伴
    2023-07-07

最新評(píng)論