Ashiquzzaman Kiron
Ashiquzzaman Kiron

Reputation: 527

Start event after TouchEnd ends

Basically I have this this mobile menu Link ( please resize the window to see mobile menu). The problem is that on mobile, users usually swipe down to see the content. Main menu on mobile. Any way to activate the "click" of the menu, upon release of the finger - instead of upon first touch? The issue is that if you're scrolling and happen to tap "menu", it opens the menu instead of scrolls. All other links on the page are fine - they only "click" when you release your finger on it (instead of first touch). So if users accidentally touch on "Menu" button, the menu opens. I want show the menu ONLY after user touch and release the menu button. To do that I'm using this code -

jQuery(document).ready(function(){
  if (window.Touch) {
    jQuery('#sidr').bind('touchstart', function(e) {
      e.preventDefault();
    });
    jQuery('#sidr').bind('touchend', function(e) {
      jQuery(this).trigger('click');
    });
  }
});

But it's not working, any suggestions ?

I just noticed the preventDefault is not working

jQuery(document).ready(function(){
jQuery('#sidr').click(function(e){
    e.preventDefault();
  })
});

Upvotes: 1

Views: 172

Answers (1)

Robbie Milejczak
Robbie Milejczak

Reputation: 5770

Try using the jQueryMobile tap handler. It will only fire after a completed touch event (i.e. on "touchend"). You can be even more restrictive and use the taphold handler, which is essentially a long touch.

Upvotes: 1

Related Questions