Longpress / longclick event support / plugin in jQuery

后端 未结 3 1038
离开以前
离开以前 2021-02-09 01:40

I\'m working on a website which requires mouseover menu\'s. I would not recommend mouseover menu\'s from an accessibility point of view, but it\'s pretty easy to implement using

3条回答
  •  自闭症患者
    2021-02-09 02:30

    You could time it.

    function onImageMouseDown(e){
        var d = new Date();
        md_time = d.getTime(); // Milliseconds since 1 Apr 1970
    }
    
    function onImageMouseUp(e){
        var d = new Date();
        var long_click = (d.getTime()-md_time)>1000;
        if (long_click){
            // Click lasted longer than 1s (1000ms)
        }else{
            // Click lasted less than 1s
        }
        md_time = 0;
    }
    

提交回复
热议问题