抽离Vant weapp滑动单元格代码改造而成
带有拉动弹性回弹效果
demo展示:https://littaotao.github.io/me/index(切换为浏览器调试的手机模式并且再次刷新一次)
SwipeCell 标记 不再关注 删除.cell_container{ position: relative; overflow: hidden; line-height: 68px; height:68px; div{ height: 100%; .cell_content{ height: 100%; width: 100%; text-align: center; } .cell_content_active{ height: 100%; width: 100%; text-align: center; &:active{ background: #e8e8e8; } } .cell_left,.cell_right{ position: absolute; top: 0; height: 100%; display: flex; color: #fff; .divPostion{ position: absolute; } div{ white-space:nowrap; display: flex; align-items: center; background: #ccc; } } .cell_left{ left: 0; transform:translateX(-100%); } .cell_right{ right: 0; transform:translateX(100%); } } }
touch.js
import Vue from 'vue';
export const isServer=false;
const MIN_DISTANCE = 10;
const TouchMixinData = {
startX: Number,
startY: Number,
deltaX: Number,
deltaY: Number,
offsetX: Number,
offsetY: Number,
direction: String
};
function getDirection(x,y) {
if (x > y && x > MIN_DISTANCE) {
return 'horizontal';
}
if (y > x && y > MIN_DISTANCE) {
return 'vertical';
}
return '';
}
export let supportsPassive = false;
export function on(
target,
event,
handler,
passive = false
) {
if (!isServer) {
target.addEventListener(
event,
handler,
supportsPassive ? { capture: false, passive } : false
);
}
}
export const TouchMixin = Vue.extend({
data() {TouchMixinData
return { direction: '' } ;
},
methods: {
touchStart() {
this.resetTouchStatus();
this.startX = event.touches[0].clientX;
this.startY = event.touches[0].clientY;
},
touchMove() {
const touch = event.touches[0];
this.deltaX = touch.clientX - this.startX;
this.deltaY = touch.clientY - this.startY;
this.offsetX = Math.abs(this.deltaX);
this.offsetY = Math.abs(this.deltaY);
this.direction =
this.direction || getDirection(this.offsetX, this.offsetY);
},
resetTouchStatus() {
this.direction = '';
this.deltaX = 0;
this.deltaY = 0;
this.offsetX = 0;
this.offsetY = 0;
},
// avoid Vue 2.6 event bubble issues by manually binding events
// https://github.com/youzan/vant/issues/3015
bindTouchEvent( el ) {
const { onTouchStart, onTouchMove, onTouchEnd } = this;
on(el, 'touchstart', onTouchStart);
on(el, 'touchmove', onTouchMove);
if (onTouchEnd) {
on(el, 'touchend', onTouchEnd);
on(el, 'touchcancel', onTouchEnd);
}
},
},
});
引入即可!!!
到此这篇关于vue swipeCell滑动单元格(仿微信)的实现示例的文章就介绍到这了,更多相关vue swipeCell滑动单元格内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!



