代碼如下:
html
<view class="container"> <view class="main"> <view class="main_item"> <movable-area> <movable-view damping="100" out-of-bounds="true" direction="horizontal" x="{{x}}" animation="false" bindchange="handleMovableChange" capture-bind:touchstart="handleTouchestart" capture-bind:touchend="handleTouchend"> <view class="main_item_content "> 左滑刪除 </view> </movable-view> </movable-area> <view class="delete_btn " data-productIndex="{{index}} " bindtap="handleDeleteProduct ">刪除</view> </view> </view> </view>
css:
.container { padding: 0; } page { padding: 0; } .main { display: flex; flex-direction: column; align-items: center; } .main_item { display: flex; flex-direction: row; background: #fff; overflow: hidden; } movable-area { width: 532rpx; height: 201rpx; background: #fff; } movable-view { width: 716rpx; height: 201rpx; } .main_item_content { box-sizing: border-box; height: 201rpx; border-radius: 10rpx; line-height: 201rpx; color: #8e8e8e; padding-left: 10px; background: #eee; } .delete_btn { width: 184rpx; height: 201rpx; background-color: #8FC31F; border-top-right-radius: 10px; border-bottom-right-radius: 10px; color: #fff; font-size: 28rpx; text-align: center; line-height: 201rpx; }
js:
// pages/listDel/index.js Page({ /** * 頁面的初始數據 */ data: { // x軸方向的偏移 x: 0, // 當前x的值 currentX: 0 }, handleMovableChange: function(e) { // this.data.currentX = e.detail.x; this.data.currentX = e.detail.x; }, handleTouchend: function(e) { this.isMove = true; if (this.data.currentX < -46) { this.data.x = -92; this.setData({ x: this.data.x }); } else { this.data.x = 0; this.setData({ x: this.data.x }); } }, handleTouchestart: function(e) {}, /** * 生命周期函數--監聽頁面加載 */ onLoad: function(options) { // let _this = this; // wx.createSelectorQuery().selectAll('.delBtn ').boundingClientRect(function(rect) { // _this.data.delWidth = rect[0].width; // }).exec(); }, /** * 生命周期函數--監聽頁面初次渲染完成 */ onReady: function() { }, /** * 生命周期函數--監聽頁面顯示 */ onShow: function() { }, /** * 生命周期函數--監聽頁面隱藏 */ onHide: function() { }, /** * 生命周期函數--監聽頁面卸載 */ onUnload: function() { }, /** * 頁面相關事件處理函數--監聽用戶下拉動作 */ onPullDownRefresh: function() { }, /** * 頁面上拉觸底事件的處理函數 */ onReachBottom: function() { }, /** * 用戶點擊右上角分享 */ onShareAppMessage: function() { } })
2:touchstart、touchmove 如果大家想了解的更清楚可以查看幫助文檔的哦
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com