Get the duration of a touch in javascript

前端 未结 3 916
抹茶落季
抹茶落季 2020-12-17 04:35

Is it possible to get the duration of a touch using javascript on ios devices (and others if possible)? I would like to differentiate a long press from a short \"click\" pre

3条回答
  •  Happy的楠姐
    2020-12-17 04:44

    You can check the time to identify Click or Long Press [jQuery]

    function AddButtonEventListener() {
    try {
    var mousedowntime;
    var presstime;
    $("button[id$='" + buttonID + "']").mousedown(function() {
        var d = new Date();
        mousedowntime = d.getTime();
    });
    $("button[id$='" + buttonID + "']").mouseup(function() {
        var d = new Date();
        presstime = d.getTime() - mousedowntime;
        if (presstime > 999/*You can decide the time*/) {
            //Do_Action_Long_Press_Event();
        }
        else {
            //Do_Action_Click_Event();
        }
    });
    }
    catch (err) {
    alert(err.message);
    }
    } 
    

提交回复
热议问题