mobile dropdown

Unobtrusive page changer for mobile view.

{code type=php}

// DOM ready
jQuery(function() {

// Create the dropdown base
jQuery(“”).appendTo(“.menu-mainmenu-container”);

// Create default option “Go to…”
jQuery(“”, {
“selected”: “selected”,
“value” : “”,
“text” : “Go to…”
}).appendTo(“.menu-mainmenu-container select”);

// Populate dropdown with menu items
jQuery(“.menu-mainmenu-container ul li a”).each(function() {
var el = jQuery(this);
jQuery(“”, {
“value” : el.attr(“href”),
“text” : el.text()
}).appendTo(“.menu-mainmenu-container select”);
});

// To make dropdown actually work
jQuery(“.menu-mainmenu-container select”).change(function() {
window.location = jQuery(this).find(“option:selected”).val();
});
});

{/code}
ref
css-tricks

Advertisements