简体   繁体   中英

on touch anywhere hide modal / tooltip / lightbox on mobile safari

I'm building a page specifically for touch devices. There are menu items on the page itself, when you touch the menu, a DIV shows. However, I like to hide the DIV once the users taps any area outside of the DIV.

I know on desktop, you can have hover effect on menu, and shows a DIV, and that mimics the effect I want on mobile where you touch anywhere, the menu hides.

But How can I archive this specifically using touch gestures and not hover?

Heres a sample code so far: http://jsfiddle.net/calebo/E5vvm/

One way of doing it is to bind the body "click" event and as soon as it is clicked, hide the "star" div and unbind the body "click" event, it is dirty, but it is working...

$(document).ready(function() {
  $('.widget-stars').bind('click', function() {
    event.preventDefault();
    $('#star').fadeIn(function() {
      $( "#star" ).parents( "body" ).bind( "click", function() {
        $( "#star" ).fadeOut();
        $( this ).unbind( "click" );
      });
    });
  });
});

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