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

前端 未结 8 2044
抹茶落季
抹茶落季 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:26

    The simplest approach is to use a multitouch JavaScript library like Hammer.js. Then you can write code like:

    canvas
        .hammer({prevent_default: true})
        .bind('doubletap', function(e) { // And double click
            // Zoom-in
        })
        .bind('dragstart', function(e) { // And mousedown
            // Get ready to drag
        })
        .bind('drag', function(e) { // And mousemove when mousedown
            // Pan the image
        })
        .bind('dragend', function(e) { // And mouseup
            // Finish the drag
        });
    

    And you can keep going. It supports tap, double tap, swipe, hold, transform (i.e., pinch) and drag. The touch events also fire when equivalent mouse actions happen, so you don't need to write two sets of event handlers. Oh, and you need the jQuery plugin if you want to be able to write in the jQueryish way as I did.

提交回复
热议问题