mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[bugfix] CellSwipe: only trigger swipe when drag horizontally (#866)
This commit is contained in:
parent
a5ddfeee68
commit
dc4b7cd5c3
@ -96,8 +96,9 @@ export default create({
|
|||||||
|
|
||||||
startDrag(event) {
|
startDrag(event) {
|
||||||
this.draging = true;
|
this.draging = true;
|
||||||
this.startX = event.touches[0].pageX;
|
this.direction = '';
|
||||||
this.startY = event.touches[0].pageY;
|
this.startX = event.touches[0].clientX;
|
||||||
|
this.startY = event.touches[0].clientY;
|
||||||
|
|
||||||
if (this.opened) {
|
if (this.opened) {
|
||||||
this.startX -= this.offset;
|
this.startX -= this.offset;
|
||||||
@ -105,8 +106,9 @@ export default create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onDrag(event) {
|
onDrag(event) {
|
||||||
const offsetTop = event.touches[0].pageY - this.startY;
|
const offsetTop = event.touches[0].clientY - this.startY;
|
||||||
const offsetLeft = event.touches[0].pageX - this.startX;
|
const offsetLeft = event.touches[0].clientX - this.startX;
|
||||||
|
|
||||||
if ((offsetLeft < 0 && -offsetLeft > this.rightWidth) ||
|
if ((offsetLeft < 0 && -offsetLeft > this.rightWidth) ||
|
||||||
(offsetLeft > 0 && offsetLeft > this.leftWidth) ||
|
(offsetLeft > 0 && offsetLeft > this.leftWidth) ||
|
||||||
(offsetLeft > 0 && !this.leftWidth) ||
|
(offsetLeft > 0 && !this.leftWidth) ||
|
||||||
@ -117,7 +119,9 @@ export default create({
|
|||||||
const y = Math.abs(offsetTop);
|
const y = Math.abs(offsetTop);
|
||||||
const x = Math.abs(offsetLeft);
|
const x = Math.abs(offsetLeft);
|
||||||
const swiping = !(x < 5 || (x >= 5 && y >= x * 1.73));
|
const swiping = !(x < 5 || (x >= 5 && y >= x * 1.73));
|
||||||
if (swiping) {
|
this.direction = this.direction || this.getDirection(event.touches[0]);
|
||||||
|
|
||||||
|
if (swiping && this.direction === 'horizontal') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.swipeMove(offsetLeft);
|
this.swipeMove(offsetLeft);
|
||||||
};
|
};
|
||||||
@ -130,6 +134,12 @@ export default create({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getDirection(touch) {
|
||||||
|
const offsetX = Math.abs(touch.clientX - this.startX);
|
||||||
|
const offsetY = Math.abs(touch.clientY - this.startY);
|
||||||
|
return offsetX > offsetY ? 'horizontal' : offsetX < offsetY ? 'vertical' : '';
|
||||||
|
},
|
||||||
|
|
||||||
onClick(position = 'outside') {
|
onClick(position = 'outside') {
|
||||||
if (!this.offset) {
|
if (!this.offset) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user