微信小程序?qū)崿F(xiàn)左滑刪除效果源碼
一、效果
二、代碼
實(shí)現(xiàn)思路使用的是官方提供的movable-area 嵌套movable-view
1、movable-area:注意點(diǎn),需要設(shè)置其高度,否則會出現(xiàn)列表內(nèi)容重疊的現(xiàn)象。
2、由于movable-view需要向右移動,左滑的時候給刪除控件展示的空間,故 movable-area 需要左移 left: -120rpx;
3、movable-view右移left: 120rpx;。 通過 width: calc(100% - 120rpx);左劃的距離。
4、 需要給movable-view組件設(shè)置層級 z-index: 1001;越高越好至少比刪除組件層級高,避免被遮住。
5、 <view class="itemDelet">刪除</view> 的位于movable-view組件右下,左滑movable-view顯示處刪除組件。
.moveArea { display: flex; flex-direction: row; width: calc(100% + 120rpx); justify-content: center; left: -120rpx; height: 188rpx; } movable-view .movableView { display: flex; flex-direction: row; width: calc(100% - 120rpx); z-index: 1001; left: 120rpx; }
源代碼如下:
Page({ /** * 頁面的初始數(shù)據(jù) */ data: { pushedData:[{messageTitle:'餅干',messageContent:'餅干愛吃'}],//已推送數(shù)據(jù) }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad() { }, /** * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成 */ onReady() { }, /** * 生命周期函數(shù)--監(jiān)聽頁面顯示 */ onShow() { }, /** * 生命周期函數(shù)--監(jiān)聽頁面隱藏 */ onHide() { }, /** * 生命周期函數(shù)--監(jiān)聽頁面卸載 */ onUnload() { }, /** * 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動作 */ onPullDownRefresh() { }, /** * 頁面上拉觸底事件的處理函數(shù) */ onReachBottom() { }, /** * 用戶點(diǎn)擊右上角分享 */ onShareAppMessage() { }, // 退出頁面 logout:function(){ wx.navigateBack({}) }, })
xml代碼
<!--pakage_kindness_remind/pages/kindess_msg_remind/kindness_msg_remind_pg.wxml--> <!-- head --> <view class="title_search"> <view class="seeck_md"> <!-- 返回 --> <view class="logout" bindtap="logout"> <image class="logout_ic" src="/images/msg/return_back.png"> </image> <text class="logout_txt">返回</text> </view> <!--內(nèi)容模板--> <view class="msg_title_center"> <view class="msg" bindtap="open_msg"> <text class="msg_txt">數(shù)據(jù)中心</text> </view> </view> </view> <view class="logout"> <image class="logout_ic"> </image> <text class="logout_txt"></text> </view> </view> <!-- body --> <scroll-view class='scbg' scroll-y='true'> <block wx:for="{{pushedData}}" wx:key="id" wx:for-item="itemName" wx:for-index="id"> <!-- 子item父布局 --> <view class="item_parent"> <!-- 日期 4月5日 周二 8:00 --> <view class="date" wx:if="{{id==0}}">{{itemName.pushTime}} </view> <!-- --> <movable-area class="moveArea"> <movable-view class="movableView" direction="horizontal" inertia="{{true}}" out-of-bounds="{{true}}"> <view style="display: flex;flex-direction: row;width: 100%;height: 100%;"> <view class="box_item"> <!--head布局--> <view class="head_layout"> <!-- itemhead左邊模塊 天氣提醒--> <view class="head_title"> {{itemName.messageTitle}} </view> </view> <!--body布局--> <view class="body_layout"> {{itemName.messageContent}} </view> </view> </view> </movable-view> <view class="itemDelet">刪除</view> </movable-area> </view> </block> </scroll-view>
css代碼
/* pakage_kindness_remind/pages/kindess_msg_remind/kindness_msg_remind_pg.wxss */ Page { background: #f0f0f0; height: 100%; position: fixed; } /* 頭部搜索 */ /* 搜索標(biāo)題 */ .title_search { background: linear-gradient(to right, #0455a7, #62c8ec); height: 170rpx; width: 100%; display: flex; flex-direction: row; align-items: flex-end; justify-content: flex-start; } .seeck_md { display: flex; flex-direction: row; width: 100%; justify-content: flex-start; align-items: flex-end; } /* 消息 */ .msg { width: 180rpx; height: 90rpx; display: flex; flex-direction: column; justify-content: center; align-items: center; margin-right: 0rpx; margin-left: 30rpx; } .msg_title_center { width: 100%; display: flex; flex-direction: row; justify-content: center; } .msg_txt { font-size: 36rpx; height: 80rpx; width: 160rpx; margin-bottom: 20rpx; align-items: center; color: #fff; display: flex; justify-content: center; } /* 返回 */ .logout { width: 100rpx; height: 90rpx; display: flex; flex-direction: column; justify-content: center; align-items: center; margin-right: 20rpx; margin-left: 30rpx; } .logout_ic { height: 44rpx; width: 48rpx; margin-right: 2rpx; } .logout_txt { font-size: 24rpx; height: 40rpx; width: 60rpx; margin-bottom: 10rpx; align-items: flex-start; color: #fff; display: flex; justify-content: flex-start; } /* 搜索標(biāo)題 */ /* 頭部搜索 */ /* body */ .scbg { background-color: #f0f0f0; width: 100%; height: calc(100vh - 180rpx); left: 0rpx; right: 0rpx; top: 0rpx; padding-bottom: 120rpx; } /* item條目布局 */ /* item父布局 */ .item_parent { margin-top: 20rpx; } .date { display: flex; align-items: center; justify-content: center; color: #999999; font-size: 28rpx; margin-bottom: 10rpx; } /* item盒子 */ .box_item { background-color: #fff; margin-left: 25rpx; margin-right: 25rpx; border-radius: 20rpx; flex-direction: column; width: 100%; height: 160rpx; display: flex; } /* item模塊時間 */ /* item上部分布局 */ .head_layout { height: 60rpx; border-radius: 20rpx; margin-right: 20rpx; display: flex; flex-direction: row; justify-content: space-between; align-items: center; } /* 標(biāo)題 */ .head_title { width: 160rpx; display: flex; align-items: center; justify-content: flex-start; margin-left: 20rpx; color: #06c8ad; font-size: 28rpx; font-weight: 800; } /* item下部份分布局 */ .body_layout { background-color: #fff; padding-bottom: 20rpx; border-radius: 20rpx; margin-bottom: 16rpx; align-items: center; margin-left: 20rpx; margin-top: 10rpx; margin-right: 10rpx; font-size: 28rpx; color: #999999; } /* 滑動刪除移動模塊 */ .moveArea { display: flex; flex-direction: row; width: calc(100% + 120rpx); justify-content: center; left: -120rpx; height: 188rpx; } /* 滑動刪除模塊 */ .movableView { display: flex; flex-direction: row; width: calc(100% - 120rpx); z-index: 1001; left: 120rpx; } /* item刪除 */ .itemDelet { position: absolute; right: 30rpx; line-height: 160rpx; background-color: #62c8ec; margin-top: 0rpx; margin-right: 6rpx; border-bottom-right-radius: 20rpx; border-top-right-radius: 20rpx; width: 120rpx; text-align: right; padding-right: 20rpx; color: #fff; }
總結(jié)
到此這篇關(guān)于微信小程序?qū)崿F(xiàn)左滑刪除效果的文章就介紹到這了,更多相關(guān)微信小程序左滑刪除內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS函數(shù)式編程之純函數(shù)、柯里化以及組合函數(shù)
這篇文章主要介紹了JS函數(shù)式編程之純函數(shù)、柯里化以及組合函數(shù),文章對三個函數(shù)進(jìn)行分析講解,內(nèi)容也很容易理解,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2023-01-01javascript 變態(tài)的節(jié)點(diǎn)集合
今天想實(shí)現(xiàn)jQuery的unwrap效果,換言之,就是用其孩子把其父節(jié)點(diǎn)干掉。為了效率,用到文檔碎片,而取孩子時使用到childNodes(返回一個nodeList)2010-03-03javascript中使用css需要注意的地方小結(jié)
javascript中使用css需要注意的地方小結(jié),注意保留字問題。2010-09-09JavaScript使用鍵盤輸入控制實(shí)現(xiàn)數(shù)字驗(yàn)證功能
根據(jù)鍵盤輸入的keycode來判斷輸入的是什么類型來實(shí)現(xiàn)數(shù)字驗(yàn)證功能,就簡單幾行代碼就可以實(shí)現(xiàn),對js數(shù)字驗(yàn)證功能感興趣的朋友一起看下吧2016-08-08JavaScrip數(shù)組刪除特定元素的幾種方法總結(jié)
從js數(shù)組中刪除指定元素是我們每個人都遇到的問題,網(wǎng)上這方面的資料也很多,但有的時間過于久遠(yuǎn),有的內(nèi)容不夠全面,所以自己來整理下,這篇文章主要給大家總結(jié)介紹了關(guān)于JavaScrip數(shù)組刪除特定元素的多種方法,需要的朋友可以參考下。2017-09-09