【发布时间】:2014-12-16 04:19:30
【问题描述】:
我在触摸滑块上弄乱了触摸事件,并且不断收到以下错误:
使用cancelable=false 忽略取消touchmove 事件的尝试, 例如,因为滚动正在进行中并且不能 被打断了。
我不确定是什么导致了这个问题,我刚接触触摸事件,似乎无法解决这个问题。
这里是处理触摸事件的代码:
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));
}
您可以找到实际的滑块here at this pen。
如果你刷得足够快,它会抛出错误,有时会卡在刷卡的中间。仍然无法理解为什么它不起作用。任何帮助/见解将不胜感激。不知道我做错了什么。
【问题讨论】:
标签: javascript jquery event-handling slider touch