简体   繁体   English

iPad的典型CSS菜单下拉悬浮问题

[英]Typical CSS menu dropdown hover issue with iPad

We're having a common issue with hover states and CSS menus on the iPad. iPad上的悬停状态和CSS菜单存在一个常见问题。 Because it doesn't recognize hover states it's not allowing a selection. 因为它无法识别悬停状态,所以不允许选择。

We've tried most of the common workarounds like onClick="return true" and using jQuery to create a dynamic hover class to replicate :hover and a few others, which I've removed now to clean the code a bit. 我们已经尝试了大多数常见的变通方法,例如onClick="return true"并使用jQuery创建了一个动态的悬停类来复制:hover和其他一些悬停类,我现在将其删除以清除代码。 I'm sure we're missing something that should be obvious. 我敢肯定我们遗漏了一些显而易见的东西。

Any help pointing me in the right direction on this would be greatly appreciated. 在此方面为我指明正确方向的任何帮助将不胜感激。

Link: iar.suissamesser.com 链接:iar.suissamesser.com

You should look at the example here http://www.hnldesign.nl/work/code/mouseover-hover-on-touch-devices-using-jquery/ 您应该在此处查看示例http://www.hnldesign.nl/work/code/mouseover-hover-on-touch-devices-using-jquery/

It's pretty straight forward from there. 从那里开始很简单。 Good Luck, 祝好运,

I assume you are talking about the menu, correct? 我认为您是在谈论菜单,对吗? What I do in this case, is add another line to my css :hover selector. 在这种情况下,我要做的是在css :hover选择器中添加另一行。 The idea is this, on click, add a class to the #nav like ' btn1 . 这个想法是,单击后,将一个类添加到#nav例如btn1 This would also require you to add a class to your list-items. 这还需要您将一个类添加到列表项中。
CSS CSS

#nav li:hover > ul,
#nav.btn1 li.btn1 > ul {
    display: block;
}

HTML HTML

<ul class="clearfix btn1" id="nav">
  <li class="btn1"><a href="http://iar.suissamesser.com/about-us/campus">ABOUT US</a><br />
    <ul>
      <li><a href="http://iar.suissamesser.com/about-us/campus">Campus</a></li>
      <li><a href="http://iar.suissamesser.com/about-us/history-mission">History &amp; Mission</a></li>
    </ul>
  </li>
  <li class="btn2"><a href="http://iar.suissamesser.com/parents/accreditation-and-licenses" >PARENTS</a><br />
    <ul>
      <li><a href="http://iar.suissamesser.com/parents/accreditation-and-licenses">Accreditation and Licenses</a></li>

JS JS

$("#nav > li > a").on("click", toggleNav);
var toggleNav = function(evt){
  var clicked = $(this).parent().attr('class');
  $("#nav").removeClass("btn1 btn2 btn3 btn4 ...").addClass(clicked);
  evt.preventDefault();
}

Include the below code in a footer file 在页脚文件中包含以下代码

$('body').on('touchstart.dropdown', '.dropdown-menu', function (e) {
e.stopPropagation();
}

this is a late late late response, but. 这是迟到晚的回应,但是。

you dont actually have to use any kind of jquery or code, you just need to confuse or override the ipad logic in the css. 您实际上不必使用任何种类的jquery或代码,您只需要混淆或覆盖CSS中的ipad逻辑。

try this in your css 试试在你的CSS

.navigation li ul
{
display:none;
}
.navigation li:hover ul
{
display:block;  
}
.navigation > li:hover
{
background-color:#000;  
}

as i understand, this stops the ipad cascading into the li and you hitting the a href because you did a hover on the li, but, when the sub menu is open, the a becomes the next responder because the li already has a hover state active. 据我了解,这将阻止ipad级联到li中,并且您点击a href是因为您在li上进行了悬停,但是,当子菜单打开时,a成为下一个响应者,因为li已经处于悬停状态活性。

this was discovered by accident. 这是偶然发现的。

html would be like this HTML将是这样的

<ul class="navigation">
<li><a href="http://www.google.com">test link</a>
<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>
<li><a href="#www.google.com">test link</a>
<li><a href="#www.google.com">test link</a>
</ul>

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

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