触摸移动卡住忽略尝试取消触摸 [英] Touch move getting stuck Ignored attempt to cancel a touchmove
问题描述
我在触摸滑块上触摸了事件,我不断收到以下错误:
I'm messing around with touch events on a touch slider and I keep getting the following error:
无效尝试取消touchMove事件与cancelable = false,
,例如因为滚动正在进行,不能
中断。
Ignored attempt to cancel a touchmove event with cancelable=false, for example because scrolling is in progress and cannot be interrupted.
我不知道是什么导致这个问题,我是新来的触摸事件,似乎无法解决这个问题。
I'm not sure what is causing this problem, I am new to working with touch events and can't seem to fix this problem.
这是代码处理触摸事件:
Here is the code handling the touch event:
Slider.prototype.isSwipe = function(threshold) {
return Math.abs(deltaX) > Math.max(threshold, Math.abs(deltaY));
}
Slider.prototype.touchStart = function(e) {
if (this._isSliding) return false;
touchMoving = true;
deltaX = deltaY = 0;
if (e.originalEvent.touches.length === 1) {
startX = e.originalEvent.touches[0].pageX;
startY = e.originalEvent.touches[0].pageY;
this._$slider.on('touchmove touchcancel', this.touchMove.bind(this)).one('touchend', this.touchEnd.bind(this));
isFlick = true;
window.setTimeout(function() {
isFlick = false;
}, flickTimeout);
}
}
Slider.prototype.touchMove = function(e) {
deltaX = startX - e.originalEvent.touches[0].pageX;
deltaY = startY - e.originalEvent.touches[0].pageY;
if(this.isSwipe(swipeThreshold)) {
e.preventDefault();
e.stopPropagation();
swiping = true;
}
if(swiping) {
this.slide(deltaX / this._sliderWidth, true)
}
}
Slider.prototype.touchEnd = function(e) {
var threshold = isFlick ? swipeThreshold : this._sliderWidth / 2;
if (this.isSwipe(threshold)) {
deltaX < 0 ? this.prev() : this.next();
}
else {
this.slide(0, !deltaX);
}
swiping = false;
this._$slider.off('touchmove', this.touchMove).one(transitionend, $.proxy(function() {
this.slide(0, true);
touchMoving = false;
}, this));
}
您可以找到实际的滑块 在这支钢笔 。
You can find the actual slider here at this pen.
如果你快速滑动就会投掷错误有时被卡在中间的滑动。仍然不能包围我的头,为什么它不工作。任何帮助/洞察将不胜感激。不知道我在做错什么。
If you swipe through fast enough it will throw the error and sometimes get stuck in the middle of a swipe. Still can't wrap my head around why it is not working. Any help/insight would be greatly appreciated. Not sure what I am doing wrong.
推荐答案
我有这个问题,我只需要做的就是从touchend返回true
,警告消失。
I had this problem and all I had to do is return true
from touchend and the warning went away.
这篇关于触摸移动卡住忽略尝试取消触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!