小程式仿QQ側滑例子

來源:互聯網
上載者:User

標籤:web   png   text   data   sof   rgb   height   content   soft   

縮放:wxml

<!--page/one/index.wxml--><view class="page">    <view class="page-bottom">        <view class="page-content">            <view  class="wc">                <navigator url="../one/index" hover-class="navigator-hover">第一個菜單</navigator>            </view>            <view  class="wc">                <navigator url="../two/index" hover-class="navigator-hover">第二個菜單(縮放)</navigator>            </view>            <view  class="wc">                <navigator url="../three/index" hover-class="navigator-hover">第三個菜單(拖動)</navigator>            </view>            <view  class="wc">                <navigator url="../four/index" hover-class="navigator-hover">第四個菜單</navigator>            </view>        </view>    </view>    <view class="page-top {{open ? ‘c-state2‘ : ‘‘}}">        <image bindtap="tap_ch" src="../../images/btn.png"></image>        <view class="text">第二個菜單(縮放)</view>    </view></view>

  js

Page({  data:{    open : false//這個資料是用來上面一層頁面是覆蓋在螢幕上還是在旁邊  },  tap_ch: function(e){//點擊的時候設定這個屬性的值    if(this.data.open){      this.setData({        open : false//之前是開啟的話現在設定為關閉      });    }else{      this.setData({        open : true      });    }  }})

  wxss

page,.page {  height: 100%;  font-family: ‘PingFang SC‘, ‘Helvetica Neue‘, Helvetica, ‘Droid Sans Fallback‘, ‘Microsoft Yahei‘, sans-serif;}.page-bottom{  height: 100%;  width: 750rpx;  position: fixed;   background-color: rgb(0, 68, 97);  z-index: 0;}.wc{  color: white;  padding: 30rpx 0 30rpx 40rpx;}.page-content{  padding-top: 300rpx;}.page-top{  height: 100%;  position: fixed;  width: 750rpx;  background-color: rgb(57, 125, 230);  z-index: 0;  transition: All 0.4s ease;   -webkit-transition: All 0.4s ease;}.page-top image{  position: absolute;  width: 68rpx;  height: 38rpx;  left: 20rpx;  top: 20rpx;}.c-state1{//這個是平滑的  transform: rotate(0deg) scale(1) translate(75%,0%);   -webkit-transform: rotate(0deg) scale(1) translate(75%,0%); }.c-state2{//這個是帶縮放的  transform: rotate(0deg) scale(.8) translate(75%,0%);   -webkit-transform: rotate(0deg) scale(.8) translate(75%,0%); }.text{  margin: auto;  margin-top: 20rpx;  margin-left: 130rpx;  vertical-align: middle;  color: white;}

  平滑的wxml

<view class="page">    <view class="page-bottom">        <view class="page-content">            <view  class="wc">                <navigator url="../one/index" hover-class="navigator-hover">第一個菜單</navigator>            </view>            <view  class="wc">                <navigator url="../two/index" hover-class="navigator-hover">第二個菜單(縮放)</navigator>            </view>            <view  class="wc">                <navigator url="../three/index" hover-class="navigator-hover">第三個菜單(拖動)</navigator>            </view>            <view  class="wc">                <navigator url="../four/index" hover-class="navigator-hover">第四個菜單</navigator>            </view>        </view>    </view>    <view bindtouchmove="tap_drag" bindtouchend="tap_end" bindtouchstart="tap_start" class="page-top {{open ? ‘c-state1‘ : ‘‘}}">        <image bindtap="tap_ch" src="../../images/btn.png"></image>        <view class="text">第三個菜單(拖動)</view>    </view></view>

  js

// page/one/index.jsPage({  data:{    open : false,    mark: 0,    newmark: 0,    istoright:true  },  tap_ch: function(e){    if(this.data.open){      this.setData({        open : false      });    }else{      this.setData({        open : true      });    }  },  tap_start:function(e){    // touchstart事件    this.data.mark = this.data.newmark = e.touches[0].pageX;  },  tap_drag: function(e){    // touchmove事件     /*     * 手指從左向右移動     * @newmark是指移動的最新點的x軸座標 , @mark是指原點x軸座標     */    this.data.newmark = e.touches[0].pageX;    if(this.data.mark < this.data.newmark){      this.istoright = true;    }    /*     * 手指從右向左移動     * @newmark是指移動的最新點的x軸座標 , @mark是指原點x軸座標     */    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;    if(this.istoright){      this.setData({        open : true      });    }else{      this.setData({        open : false      });    }  }})

  

小程式仿QQ側滑例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.