简体   繁体   English

在iPad上下拉菜单不会消失

[英]Dropdown doesn't disappear on iPad

I have a simple dropdown button which shows content when user clicks or taps (on touch screens) the button. 我有一个简单的下拉按钮,当用户单击或点击(在触摸屏上)按钮时,它会显示内容。 It works great but on some mobile devices (especially iPad and devices with Windows Mobile), the dropdown doesn't disappear when user touch the screen outside the dropdown. 它可以正常工作,但在某些移动设备(尤其是iPad和装有Windows Mobile的设备)上,当用户触摸下拉列表外的屏幕时,下拉列表不会消失。

Here's HTML: 这是HTML:

<div class="dropdown">
    <div class="dropdown-toggle">Click Me</div>
    <div class="dropdown-menu">Example contnt of the dropdown</div>
</div>

Here's JavaScript: 这是JavaScript:

$(document).on('mouseenter', '.dropdown', function() {

    $(this).children('.dropdown-menu').show();

}).on('mouseleave', '.dropdown', function() {

    $(this).children('.dropdown-menu').hide();

});
  • Why it doesn't work on these devices? 为什么在这些设备上不起作用?
  • What other events I should use? 我还应该使用其他哪些事件?
  • And most important: how to make the dropdown disappear properly on all devices? 最重要的是:如何使下拉菜单在所有设备上正确消失? Cross-browser and cross-device solution would be great. 跨浏览器和跨设备的解决方案会很棒。

You can add the touchstart event to the following 您可以将touchstart事件添加到以下内容中

$(document).on('mouseenter touchstart', '.dropdown', function() {

And likewise, the touchend event on the mouseout 同样,mouseout上的touchend事件

}).on('mouseleave touchend', '.dropdown', function() {

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

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