Skip to content

Instantly share code, notes, and snippets.

@AndrewChamp
Last active December 24, 2018 06:16
Show Gist options
  • Save AndrewChamp/5859790 to your computer and use it in GitHub Desktop.
Save AndrewChamp/5859790 to your computer and use it in GitHub Desktop.
# http://css-tricks.com/convert-menu-to-dropdown/ Convert navigation into form Select for better usability on mobile devices.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style>
nav select{display:none;}
@media (max-width: 960px){
nav ul{display:none;}
nav select{display:inline-block;}
}
</style>
<script>
$(function() {
$("<select />").appendTo("nav");
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Go to..."
}).appendTo("nav select");
$("nav a").each(function() {
var el = $(this);
$("<option />", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo("nav select");
});
$("nav select").change(function() {
window.location = $(this).find("option:selected").val();
});
});
</script>
<nav>
<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>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment