从 dom 中移除任何元素后,Touchmove 事件停止触发
Touchmove event stops triggering after any element is removed from dom
在 iPad 等触摸设备上(或 chrome 中的 移动仿真模式 )。当跟踪 body 上的 touchmove
事件并从 dom touchmove
事件中删除元素(touchstart 开始的元素)时,body 停止触发。
我做了一个例子:http://jsbin.com/yinodosuxo/1/edit?js,console,output
有没有什么方法可以让 touchmove
在子元素被移除后继续工作?
我通过缓存元素直到发出 touchend
事件解决了这个问题。
触发 touchstart
事件的视图伪代码如下所示:
view.remove = function () {
if (didViewStartTouchEvents) {
var _this = this;
this.hideElement(); // display: none, opacity: 0, etc
elementCache.appendChild(this); //append this element to some other place like body. Not needed but might be handy depending on situation
document.body.addEventListener('touchend', function () {
_this.didViewStartTouchEvents = false;
_this.remove();
});
} else {
// regular remove & cleanup
}
}
在 iPad 等触摸设备上(或 chrome 中的 移动仿真模式 )。当跟踪 body 上的 touchmove
事件并从 dom touchmove
事件中删除元素(touchstart 开始的元素)时,body 停止触发。
我做了一个例子:http://jsbin.com/yinodosuxo/1/edit?js,console,output
有没有什么方法可以让 touchmove
在子元素被移除后继续工作?
我通过缓存元素直到发出 touchend
事件解决了这个问题。
触发 touchstart
事件的视图伪代码如下所示:
view.remove = function () {
if (didViewStartTouchEvents) {
var _this = this;
this.hideElement(); // display: none, opacity: 0, etc
elementCache.appendChild(this); //append this element to some other place like body. Not needed but might be handy depending on situation
document.body.addEventListener('touchend', function () {
_this.didViewStartTouchEvents = false;
_this.remove();
});
} else {
// regular remove & cleanup
}
}