How to replace click with touchstart on iOS devices

前端 未结 3 387
礼貌的吻别
礼貌的吻别 2020-12-09 20:29

Objective

To close the parent div of an anchor tag when clicked. In the code below, I want to hide div performance_tt when the user

3条回答
  •  Happy的楠姐
    2020-12-09 21:11

    Define a clickhandler that you can use later on:

    var clickHandler = ('ontouchstart' in document.documentElement ? "touchstart" : "click");
    
    $("a").bind(clickHandler, function(e) {
        alert("clicked or tapped. This button used: " + clickHandler);
    });
    

    This will trigger click on non-touch devices and touchstart on touch devices.

    When that is said, I will strongly recommend using Fast click instead, and use regular click-events. With the above solution, you will trigger "touchstart" on links when you swipe on it to scroll the page for instance - which is not ideal.

提交回复
热议问题