touch events firing twice

前端 未结 3 1998
天涯浪人
天涯浪人 2020-12-31 18:51

I am having problems on mobile devices/tablets with the events firing twice. When I click the following function, the menu that is supposed to drop down will drop down then

3条回答
  •  情深已故
    2020-12-31 19:12

    The following worked for me which is a slight modification for @JRules answer

    // lo is just a global object holder 
    let lo = {
        "handled":false
    }
    

    Using delegate because objects are not loaded on original page load

    $('body').delegate('.linkRow','click touchend',function(e) {  //   
        e.stopPropagation();
        if(lo.handled === false){  // check
            doSomething()                 
            lo.handled = true
        }
        setTimeout(() => {  // now set to false later (example here is 1/2 sec)
            lo.handled = false
        }, 500)
    });
    

提交回复
热议问题