【问题标题】:HTML5 section touchstart touchmove touchend iOSHTML5部分 touchstart touchmove touchend iOS
【发布时间】:2012-06-05 17:55:40
【问题描述】:

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

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 事件侦听器绑定到此部分元素时,它适用于 Android,但不适用于 iPad/iPod/iPhone。

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

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

提前致谢! =)

【问题讨论】:

    标签: javascript html ios dom-events touch-event


    【解决方案1】:

    没关系,用 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) {
        // ...
    });
    

    【讨论】:

    • 该代码将在支持触摸的浏览器中触发两次。看看: $(document).ready(function(){ $('body').bind("touchstart mousedown", function (e) { console.log("test" + Date.now()); } ); });
    • yupp,最终解决方案处理它=)
    • 似乎不适用于 $('.slider ul li').bind("touchstart mousedown", function (e) { console.log(e.type); // 获取名称事件 }).bind("touchmove mousemove", function (e) { console.log(e.type); }).bind("touchend mouseup", function (e) { console.log(e.type) ; });
    猜你喜欢
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    • 2017-04-25
    相关资源
    最近更新 更多