简体   繁体   中英

FastClick and click() event trigger trouble

I have trouble when I include FastClick in my proj. All works fine and 300ms delay on mobile devices is lost but programmatically triggering click() event doesnt work on mobile now.

It says this in the documentation (well, the page you linked under advanced)

This is where the needsclick class comes in. Add the class to any element that requires a non-synthetic click.

So add the class needsclick to the elements you want to manual trigger "click" with

I had exactly the same problem and at the end I got rid of FastClick and did my own simple solution after some problems with fastclick when triggering click events. This example uses jQuery.

$(document).on('touchstart', '.clickable', function(e){
    // This prevents the click to be completed
    // so will prevent the annoying flickering effect
    e.preventDefault();
});

You have to add .clickable class to any element you want to take out the 300m delay from.

Then, change all click events for touchstart events, so this

$('#elementid').click(function(e){
   console.log('ex event'); 
}

has to be now this

$(document).on('touchstart', '#elementid', function(e){
   console.log('new event'); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM