admin管理员组文章数量:1416623
I'm trying to create a mobile sliding (not slide-in) menu similar to how google menu is on mobile devices (as shown below).
Notice the menu there allows you to slide from left to right to show the hidden menu items (Books, etc. in this case). I would like to create this effect. Can it be done with pure CSS or is there a plugin for it?
I would like overflowing elements to be hidden at the left but a swipe should be able to bring them into focus.
My menu code looks like:
<div id="nav-wrapper">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#about">About</a></li>
<li><a data-toggle="tab" href="#settings">Settings</a></li>
<li><a data-toggle="tab" href="#option1">Option1</a></li>
<li><a data-toggle="tab" href="#option2">Option2</a></li>
<li><a data-toggle="tab" href="#option3">Option3</a></li>
</ul>
</div>
I've tried
#nav-wrapper {/* max width and height set here to hide the scroll bars of the <ul> */}
.nav-tabs {width: 300px; overflow-x: scroll; white-space: nowrap;}
problem with the code is that the overflowed <li>
elements go into a new line and are hidden.
I'm using bootstrap and AngularJS by the way.
I'm trying to create a mobile sliding (not slide-in) menu similar to how google. menu is on mobile devices (as shown below).
Notice the menu there allows you to slide from left to right to show the hidden menu items (Books, etc. in this case). I would like to create this effect. Can it be done with pure CSS or is there a plugin for it?
I would like overflowing elements to be hidden at the left but a swipe should be able to bring them into focus.
My menu code looks like:
<div id="nav-wrapper">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#about">About</a></li>
<li><a data-toggle="tab" href="#settings">Settings</a></li>
<li><a data-toggle="tab" href="#option1">Option1</a></li>
<li><a data-toggle="tab" href="#option2">Option2</a></li>
<li><a data-toggle="tab" href="#option3">Option3</a></li>
</ul>
</div>
I've tried
#nav-wrapper {/* max width and height set here to hide the scroll bars of the <ul> */}
.nav-tabs {width: 300px; overflow-x: scroll; white-space: nowrap;}
problem with the code is that the overflowed <li>
elements go into a new line and are hidden.
I'm using bootstrap and AngularJS by the way.
Share Improve this question edited Nov 7, 2016 at 1:41 Whymarrh 13.6k15 gold badges61 silver badges110 bronze badges asked Nov 7, 2016 at 0:40 Joshua KissoonJoshua Kissoon 3,3296 gold badges33 silver badges60 bronze badges 4- "I've been trying to figure out how to get this done for quite a while now and have tried a few things." What doesn't work? – Whymarrh Commented Nov 7, 2016 at 0:59
- can you edit your question and hit CTRL + M and paste what code you have tried in the box? – mlegg Commented Nov 7, 2016 at 1:06
- @Whymarrh I've tried setting a max width to the <ul> and putting overflow: scroll; while hiding the scroll bars - problem with this is that the overflowed element doesn't stay in the same line. – Joshua Kissoon Commented Nov 7, 2016 at 1:28
- better to include what you've done so far. :) – claudios Commented Nov 7, 2016 at 1:30
1 Answer
Reset to default 3Your li
elements need to be displayed as inline-blocks. Use ::-webkit-scrollbar-
to customise the scrollbar in Webkit/Blink browsers on desktop. Set a max-width on the wrapper, make sure the ul
is set to display as a block element and has no width constraints.
In the demo below, the width of the container is arbitrary; I just chose 400px to demonstrate the overflowing.
Fiddle: https://jsfiddle/5guzupzd/
::-webkit-scrollbar { width:0; height:0 }
::-webkit-scrollbar-thumb { background: transparent}
::-webkit-scrollbar-track { background-color: transparent}
* {
box-sizing: border-box
}
#nav-wrapper {
border:3px solid #444;
max-width: 400px;
margin: 0 auto;
}
ul,li {
list-style: none;
padding: 0
}
.nav.nav-tabs {
-webkit-overflow-scrolling: touch; /* apply iOS momentum scrolling effect to this element */
display: block;
overflow: auto;
white-space: nowrap
}
.nav.nav-tabs li {
display: inline-block
}
.nav.nav-tabs li a {
display: block;
background: mediumblue;
color: #fff;
padding: 16px
}
<div id="nav-wrapper">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#about">About</a></li>
<li><a data-toggle="tab" href="#settings">Settings</a></li>
<li><a data-toggle="tab" href="#option1">Option1</a></li>
<li><a data-toggle="tab" href="#option2">Option2</a></li>
<li><a data-toggle="tab" href="#option3">Option3</a></li>
</ul>
</div>
本文标签: javascriptCSS (Mobile version of site) Sliding Menu via swipeStack Overflow
版权声明:本文标题:javascript - CSS (Mobile version of site) Sliding Menu via swipe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745251827a2649867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论