How can I make it difficult to trigger click events twice?

  • I have a single page application.
  • It uses backbone.js.
  • Click mouse events with one click.
  • Double-tap events using the touch device.
  • Disabling the one-click event stops like on touch devices.

I can’t figure out where to start looking.

This is JS:

$('.classy').on('click', 'button', function(){ console.log('clicked'); }) 

I need help figuring out how to do this. I know that I have not received enough information to get a real answer. What puzzles me is that this only happens on touch devices. If I accidentally linked two events or created two instances of the same view, would that not be the case for mouse clicks?

Thanks.

EDIT: I tried using the tap event via jQuery Mobile. It had a strange reaction. He once triggered an event and looked like it was done, but the next time you touch anywhere on the screen, he will fire the event again .... weird, any ideas?

I finally found the problem. This came from layered iScrolls. I should have hacked lib at this point, probably a much better way to fix this, but illustrated the gist.

 if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA' && window.iScrollClickFIX != true) { window.iScrollClickFIX = true; setTimeout(function(){ window.iScrollClickFIX = false; }, 1) 

Thanks for helping everyone.

+3
source share
5 answers

It may not be the actual solution ... Just think

 $('.classy').die('click').on('click', 'button', function(){ console.log('clicked'); }) 
+1
source

Try changing the binding to mousedown instead of click ?

(if you use click )

0
source

Perhaps there is another parent element to which you have also assigned a click handler. Try this to prevent a click (or any other event) causing the DOM to fire:

 $('.classy').on('click', 'button', function(e){ console.log('clicked'); e.stopPropagation(); }) 
0
source

The first thing I would do to prevent shooting is to set a breakpoint using the debugger in Chrome / IE / Firefox to make sure that the binding is not done twice.

Or try the following:

 $('.classy').off('click').on('click', 'button', function(){ console.log('clicked'); }) 
0
source

You can use the jquery one function instead of clicking to get rid of double-click problems.

0
source

Source: https://habr.com/ru/post/1386286/


All Articles