简体   繁体   English

在平板电脑/手机上重用Nav作为下拉菜单

[英]Reusing Nav as dropdown menu on tablet/mobile

I have created a nav which hides and displays the menu items and displays a menu icon when on tablet/mobile view. 我创建了一个导航栏,该导航栏在平板电脑/移动设备视图上隐藏并显示菜单项,并显示菜单图标。

How can this be adapted that when clicked on, the menu items drop down? 单击该菜单项时如何使其适应下拉菜单?

HTML: HTML:

<nav class="site-nav">
  <ul>
    <li><a href="index.html"><span class="icon-home"></span></a></li>
    <li><a href="#">Menu 1</a></li> 
    <li><a href="#">Menu 2</a></li> 
    <li><a href="#">Menu 3</a></li>
    <li><a href="#">Menu 4</a></li>
    <li><a href="#">Menu 5</a></li>
  </ul>
</nav>
<a class="navicon-button x">
  <div class="navicon"></div>
</a>

Here's my codepen: http://codepen.io/anon/pen/WbbRvK?editors=110 这是我的代码笔: http ://codepen.io/anon/pen/WbbRvK?editors=110

I would recommend looking here 我建议看这里

If you scroll to the bottom it shows how to do DOM manipulation with event handling as well. 如果滚动到底部,它将显示如何通过事件处理进行DOM操作。

My guess is that when the user clicked on the link you would change the CSS of the sub menu: 我的猜测是,当用户单击链接时,您将更改子菜单的CSS:

var location = {
     left: element[0].left,
     top: element[0].top
    };

var subMenu = angular.element('.subMenu');
subMenu.css({
     position: 'absolute',
     top: location.top + 50 + "px",
     left: location.left + "px",
     cursor: 'pointer'
    });

Obviously this isn't a complete solution, but thats for you to figure ;), hopefully I have pointed you in the right direction! 显然,这不是一个完整的解决方案,但这就是您的理想选择;),希望我已为您指明了正确的方向!

Bootstrap makes this quite easy, provided that you are able/happy to add it to your project. 如果您能够/很高兴将其添加到项目中,Bootstrap将使此操作非常容易。

See the example navbar demo here . 此处查看示例navbar演示。

You can achieve it by a checkbox hack. 您可以通过复选框黑客来实现。

refer this tut: http://css-tricks.com/the-checkbox-hack/ 请参考此教程: http : //css-tricks.com/the-checkbox-hack/

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

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