jsweb
// pages/text/text.js Page({ data: { side: {//滑動操做 pageX: 0, newpageX: 0, open: false, newopen: false,//判斷側邊欄是否打開-顯示 }, }, tap_click: function () {//點擊菜單 this.data.side.open = !this.data.side.open; this.setData({ 'side.newopen': this.data.side.open }); }, tap_start: function (e) {//touchstart事件 this.data.side.pageX = this.data.side.newpageX = e.touches[0].pageX; }, tap_move: function (e) {//touchmove事件 this.data.side.newpageX = e.touches[0].pageX; }, tap_end: function () {//touchend事件 if (this.data.side.pageX != this.data.side.newpageX) { this.data.side.open = this.data.side.pageX > this.data.side.newpageX ? true : false; this.setData({ 'side.newopen': this.data.side.open }); } }, })
wxmlxss
<view class="page"> <view bindtouchmove="tap_move" bindtouchend="tap_end" bindtouchstart="tap_start" class="content {{side.newopen?'state':''}}"> <image bindtap="tap_click" src="../../static/nav_icon_miaoSha.png" style='width:2rem;height:2rem'></image> </view> <view class="side"><!--側滑菜單--> <text>內容</text> </view> </view>
wxsside
/* pages/text/text.wxss */ .side{ height: 100%; width: 750rpx; position: fixed; background: #C1C1C1; } .content{ height: 100%; width: 750rpx; position: fixed; background:#2B9BEB; transition: All 0.5s ease; -webkit-transition: All 0.5s ease; z-index: 2; } .state{ transform: rotate(0deg) scale(1) translate(-70%,0%); -webkit-transform: rotate(0deg) scale(1) translate(-70%,0%); }