简体   繁体   English

随时随地触摸隐藏移动浏览器上的模式/工具提示/灯箱

[英]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. 页面本身上有菜单项,当您触摸菜单时,将显示DIV。 However, I like to hide the DIV once the users taps any area outside of the DIV. 但是,我喜欢在用户点击DIV之外的任何区域后隐藏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. 我知道在桌面上,您可以在菜单上具有悬停效果,并显示DIV,这类似于我希望在您触摸任何地方的移动设备上产生的效果,菜单会隐藏。

But How can I archive this specifically using touch gestures and not hover? 但是我该如何使用触摸手势而不是将鼠标悬停来专门存档呢?

Heres a sample code so far: http://jsfiddle.net/calebo/E5vvm/ 到目前为止,这里是示例代码: 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... 一种方法是绑定主体“ click”事件,并在单击它时立即隐藏“ star” div并取消绑定主体“ click”事件,它很脏,但是可以正常工作...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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