最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML5 section touchstart touchmove touchend iOS - Stack Overflow

programmeradmin2浏览0评论

Please somebody help me with this:

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;

I have a section element, generated dynamically by JavaScript (ul > li > section). When I'm binding a touchstart-touchmove-touchend event listener to this section element, it works on Android, but not on iPad/iPod/iPhone.

I have tried generating it with onclick="void(0)" attribute, it made the section element "interact" like a clickable element but it still does nothing.

It works on Android every way but this vegetable seems a little consume useless to me now... =)

Thanks in advance! =)

Please somebody help me with this:

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;

I have a section element, generated dynamically by JavaScript (ul > li > section). When I'm binding a touchstart-touchmove-touchend event listener to this section element, it works on Android, but not on iPad/iPod/iPhone.

I have tried generating it with onclick="void(0)" attribute, it made the section element "interact" like a clickable element but it still does nothing.

It works on Android every way but this vegetable seems a little consume useless to me now... =)

Thanks in advance! =)

Share Improve this question edited Nov 22, 2019 at 19:36 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked May 31, 2012 at 13:04 benqusbenqus 1,1472 gold badges10 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Nevermind, got it with jQuery. This way it runs everywhere.

$(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) {
    // ...
});
发布评论

评论列表(0)

  1. 暂无评论