javascript - HTML5 部分 touchstart touchmove touchend iOS

标签 javascript html ios dom-events touch-event

请有人帮我解决这个问题:

touchStart = function (evt) {
    evt.preventDefault();
    $(this).addClass("touched");
};

touchEnd = function (evt) {
    evt.preventDefault();
    $(this).removeClass("touched");
};

s.ontouchstart = touchStart;
s.ontouchend = touchEnd;
s.ontouchmove = touchEnd;

我有一个 section 元素,由 JavaScript 动态生成 (ul > li > section)。当我将 touchstart-touchmove-touchend 事件监听器绑定(bind)到此部分元素时,它适用于 Android,但不适用于 iPad/iPod/iPhone。

我已经尝试使用 onclick="void(0)" 属性生成它,它使 section 元素像可点击元素一样“交互”,但它仍然什么都不做。

它在 Android 上的所有方面都适用,但这种蔬菜现在对我来说似乎有点消耗无用... =)

提前致谢! =)

最佳答案

没关系,用 jQuery 搞定了。这样它就可以到处运行。

$(s).bind("touchstart mousedown", function (e) {
    console.log(e.type); // to get the name of the event
}).bind("touchmove mousemove", function (e) {
    // ...
}).bind("touchend mouseup", function (e) {
    // ...
});

关于javascript - HTML5 部分 touchstart touchmove touchend iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10834222/

相关文章:

html - SCSS/CSS 最近父级选择器

iphone - 具有可变振荡模式的 iOS 音调发生器

ios - LinkedIn URL方案可在iPad中打开公司资料

javascript - 2个数组值之一颜色之一使D3条形图在相同的值索引处具有颜色

javascript - NGRX:创建多个 reducer react 的 "global"操作的正确方法?

javascript - 如何在SAPUI5中调用php webservice url?

javascript - Grunt sass 不输出任何 css

javascript - 使用 append() 动态添加一个 div

javascript - 保留具有相同名称的多个复选框的复选框状态

ios - 在 iOS 应用程序中检测 AirPlay 镜像