How can I recognize touch events using jQuery in Safari for iPad? Is it possible?

前端 未结 8 1896
抹茶落季
抹茶落季 2020-11-22 13:09

Is it possible to recognize touch events on the iPad\'s Safari browser using jQuery?

I used mouseOver and mouseOut events in a web application. Are there any simila

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 13:29

    Core jQuery doesn't have anything special for touch events, but you can easily build your own using the following events

    • touchstart
    • touchmove
    • touchend
    • touchcancel

    For example, the touchmove

    document.addEventListener('touchmove', function(e) {
        e.preventDefault();
        var touch = e.touches[0];
        alert(touch.pageX + " - " + touch.pageY);
    }, false);
    

    This works in most WebKit based browsers (incl. Android).

    Here is some good documentation.

提交回复
热议问题