在移动Safari上触摸任何地方隐藏模式/工具提示/灯箱

发布于 2024-12-19 20:15:31 字数 310 浏览 2 评论 0原文

我正在专门为触摸设备构建一个页面。 页面本身有菜单项,当您触摸菜单时,会显示一个 DIV。 但是,我喜欢在用户点击 DIV 之外的任何区域后隐藏 DIV。

我知道在桌面上,您可以在菜单上有悬停效果,并显示 DIV,这模仿了我在移动设备上想要的效果,您触摸任何地方,菜单就会隐藏。

但是我怎样才能专门使用触摸手势而不是悬停来存档呢?

到目前为止,这是一个示例代码: http://jsfiddle.net/calebo/E5vvm/

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/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨落星ぅ辰 2024-12-26 20:15:31

一种方法是绑定主体“单击”事件,一旦单击,隐藏“星”div并取消绑定主体“单击”事件,它很脏,但它正在工作......

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

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" );
      });
    });
  });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文