微信小程序?qū)崿F(xiàn)滑動(dòng)側(cè)邊欄
本文實(shí)例為大家分享了微信小程序滑動(dòng)側(cè)邊欄的具體代碼,供大家參考,具體內(nèi)容如下
效果圖:

手指向右滑動(dòng)可以顯示側(cè)邊欄,向左滑動(dòng)隱藏側(cè)邊欄
代碼附上:.wxml
<view class="title">
? ? ? <image ?class='headPortrait' src='../../images/1.jpg'></image> ?
? ? ? ? ? ? ?<text>趙國(guó)偉</text> ?
? ? ? ? ? ? </view>
? ? ? ? ? ? <view class="nav_left_items {{click == 1 ? 'active' : ''}}"?
? ? ? ? ? bindtap="switchRightTab" ?data-id="1" >
? ? ? ? ? ? ? ? <image ?class='icon' src='../../images/get.png'></image>
? ? ? ? ? ? ? ? <view>收件箱
? ? ? ? ? ? </view>
? ? ? ? ? ? </view>
? ? ? ? ? ? <view class="nav_left_items {{click == 2 ? 'active' : ''}}"?
? ? ? ? ? bindtap="switchRightTab" ?data-id="2">
? ? ? ? ? ? ? ? <image ? class='icon' src='../../images/send.png'></image>
? ? ? ? ? ? ? ? <view>發(fā)件箱
? ? ? ? ? ? </view>
? ? ? ? ? ? </view>
? ? ? ? ? ? <view class="nav_left_items {{click == 3 ? 'active' : ''}}"?
? ? ? ? ? bindtap="switchRightTab" ?data-id="3">
? ? ? ? ? ? ? ? <image ? class='icon' src='../../images/write.jpg'></image>
? ? ? ? ? ? ? ? <view >寫信件
? ? ? ? ? ? </view>
? ? ? ? </view>
</scroll-view>.js文件
?tap_ch: 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
? ? ? ? });
? ? }
},.wxss文件
.nav_left{
? ? width:25%;
? ? height:100%;
? ? background:#F2F2F2;
? ? text-align:center;
? ? position:absolute;
? ? top:0;
? ? left:0;
? }
? .nav_left .nav_left_items{
? ? ? display: flex;
? ? height:40px;
? ? line-height:40px;
? ? font-size:28rpx;
? }
? .nav_left .nav_left_items.active{
? ? ? display: flex;
? ? background: #fff; ?/* 背景色變成白色 */ ?
? color: #3385ff; ? ?/* 字體編程藍(lán)色 */
? border-left: 3px solid #3385ff; ?/* 設(shè)置邊框的寬度以及顏色 */
? }
.title{
? ? margin-top: 10px;
}
.icon{
? ? display: flex;
? ? justify-content: center;
? ? align-items: center;
? ? width:20px;
? ? height: 20px;
? ? margin: 0px 3px;
? ? border-radius: 5px ;
? ? margin-top:10px ;?
}
.headPortrait{
? ? width:28px;
? ? height: 28px;
? ? border-radius: 20px;
}
.page-slidebar {
? height: 100%;
? width: 750rpx;
? position: fixed;
? background-color:white;
? z-index: 0;
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
js實(shí)現(xiàn)n秒倒計(jì)時(shí)后才可以點(diǎn)擊的效果
這篇文章主要介紹了js點(diǎn)擊按鈕在倒計(jì)時(shí)后才可以點(diǎn)擊的效果,需要的朋友可以參考下2015-12-12
JavaScript 大數(shù)據(jù)相加的問(wèn)題
寫一個(gè)函數(shù)處理大數(shù)據(jù)的相加問(wèn)題,所謂的大數(shù)據(jù)是指超出了整型,長(zhǎng)整型之類的常規(guī)數(shù)據(jù)類型表示范圍的數(shù)據(jù)。實(shí)現(xiàn)語(yǔ)言不限。2011-08-08
js光標(biāo)定位文本框回車表單提交問(wèn)題的解決方法
這篇文章主要介紹了js光標(biāo)定位文本框回車表單提交問(wèn)題的解決方法,涉及javascript阻止瀏覽器默認(rèn)事件的方法,需要的朋友可以參考下2015-05-05
JavaScript實(shí)現(xiàn)圖片自動(dòng)加載的瀑布流效果
這篇文章主要介紹了JavaScript實(shí)現(xiàn)圖片自動(dòng)加載的瀑布流效果的相關(guān)資料,需要的朋友可以參考下2016-04-04
JavaScript實(shí)現(xiàn)五子棋游戲的方法詳解
這篇文章主要介紹了JavaScript實(shí)現(xiàn)五子棋游戲的方法,結(jié)合實(shí)例形式詳細(xì)分析了javascript實(shí)現(xiàn)五子棋游戲的具體步驟、原理與相關(guān)操作技巧,需要的朋友可以參考下2019-07-07

