简体   繁体   English

iPhone上的触摸菜单–是否可以通过使用简单的标记并结合:hover状态来实现?

[英]Touch menu on iPhone – can it be realized by using simple markup, incorporating the :hover-state?

Today I have launched a WordPress blog it took me much time to develop the theme for. 今天,我启动了一个WordPress博客,花费了很多时间来开发主题。 Now it was the first time I could request the site via iPhone I was just shocked. 现在,这是我第一次可以通过iPhone请求该网站,这让我感到震惊。 I thought it would be a simple task to realize a touch menu by writing simple HTML and styling it taking advantage of the :hover-state to display or not display it's content. 我认为通过编写简单的HTML并使用:hover-state来显示或不显示其内容来实现触摸菜单将是一项简单的任务。

If you switch your Browser to a mobile user agent and load this site (make the window about 640px wide before), you will see my light blue widget bar. 如果将浏览器切换到移动用户代理并加载此网站 (之前使窗口宽约640像素),您将看到我的浅蓝色小部件栏。 Hovering over the icons on it will toggle the inner containers with the main widget contents — works like a charm. 将鼠标悬停在其上的图标上将切换带有主要小部件内容的内部容器-就像一个饰物。

Unfortunately, when I call the site on my iPhone, that bar with the icons will appear but will not be touchable at all. 不幸的是,当我在iPhone上致电该网站时,带有图标的栏会出现,但根本无法触摸。 Damn! 该死的! What's wrong with my code? 我的代码有什么问题? I hope you can help me. 我希望你能帮助我。 Thanks in advance 提前致谢

Here is what I found with hover in iOS. 这是我在iOS中使用悬停时发现的内容。 http://www.websitecodetutorials.com/code/iPhone-&-iPad/apple-iPhone-iPad-IOS-simulate-hover.php . http://www.websitecodetutorials.com/code/iPhone-&-iPad/apple-iPhone-iPad-IOS-simulate-hover.php It may be the fix to your problem. 这可能是解决您的问题的方法。 Or others down the road. 或其他人。

"With the rule -webkit-transition:all 0.3s ease-in-out; (and possibly others) in place iOS won't hover unless you add display:none/display:block or display:table/display:block. Additionally I found that, without the hover code in place, if you actually have a destination link in the href, upon clicking it, it just strait launches to it. With the code in place, you click once for hover event, and an additional time to follow the link. So if you find the iOS device won't (or correctly) hover for whatever reason here is your probable fix." “有了规则-webkit-transition:all 0.3s easy-in-out;(以及其他可能),iOS不会徘徊,除非您添加display:none / display:block或display:table / display:block。此外我发现,如果没有正确的悬停代码,则如果在href中确实有一个目标链接,则单击该链接时,它将立即启动到该链接;有了代码,则单击一次进行悬停事件,然后再单击一次按照链接进行操作。因此,如果您发现iOS设备由于某种原因不会(或正确)悬停,则可能是您的修正。”

Now I figured out I never could get it working the way I wanted when posting this question (I'm sorry the link doesn't show it anymore). 现在,我发现发布此问题时,我永远无法以我想要的方式工作(很抱歉,链接不再显示该链接)。 Explanation: My markup was like: 说明:我的标记就像:

<li class="widget-container">
    <p class="widget-title">Categories</p>
    <div class="widget-content">
        <ul>...</ul>
    </div>
</li>

The style was like: 风格就像:

.widget-content                         {display:none}
.widget-container:hover .widget-content {display:block}

I'd love to code as simple as this but it won't work for a good reason: On touch devices, the touch-action is always targeting the uppermost object in z-index which in this example would be the .widget-title . 我很喜欢这样简单的代码,但是由于一个很好的原因而无法正常工作:在触摸设备上,触摸操作始终以z-index中的最高对象为目标,在本示例中为.widget-title Thatfor, the wrapping .widget-container can never be touched and thus its :hover -state will never be triggered. 为此,包装的.widget .widget-container永远不会被触摸,因此它的:hover -state将永远不会被触发。

This exercise made me recognize a touch-screen-optimized site has to incorporate JavaScript to work well. 这项练习使我认识到,针对触摸屏进行了优化的网站必须结合JavaScript才能正常工作。 So I came up with a jQuery accordion solution now. 因此,我现在想出了一个jQuery手风琴解决方案。

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

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